Hi, i’m wan’t to make grid placement system but i have a trouble with one thing,
how i can round number to nearest value that center aren’t 0.
for example we have our number X that we wan’t to round, then we have number Y that is our multiplier (when Y is 4 and X is 2 we wan’t to round X to Y) but with center of number Z
as you can see i have big problem with rounding to value that is continuation of Z+Y
for example, if our X is 5 and we wan’t round it to value on our specific number line, we rounding it to 3 instead of 4 , but if we have 9 for example , we wan’t to round this to 7 because 7 = 3+4 , anyone know how to do this like operation?
For this example I used 4 as the grid size, but you can use whatever you want by making the first number half the second number.
If value < 2 then
value = 0
else
value = 4
end
You could also do a calculation to divide it by 4, round it, then multiply it by 4 to get the same result.
Also @hollywoodleaks they now have math.round instead of math.floor to properly round decimal numbers.
If you want to make a specific grid you can use this:
local GridSize = 5
local function GetBlockPosition(PositionOf)
return Vector3.new(math.floor(PositionOf.X/GridSize)*GridSize,math.floor(PositionOf.Y/GridSize)*GridSize, math.floor(PositionOf.Z/GridSize)*GridSize)
end