How would you go by making a placement system that works on a grid placement?
I AM NOT ASKING FOR CODE I know how to make everything else OTHER than how to make it work on a grid, how would you go by making a standard placement system to a grid placement system? Like what would you use?
I seen people use modulus (%) and then subtract to make it work on a grid but I don't understand the reasoning behind it, can anyone explain how it works?
If all you need to do is snap a part's position to a grid you could do something like this
function Snap(number, to) return math.floor((number / to) + .5) * to end -- We can now snap any number to our grid local gridSize = 5 -- Snap to nearest 5 studs MyPart.Position = Vector3.new(Snap(x, gridSize), 0, Snap(z, gridSize))
All the Snap
function does is round a number to the nearest x
Example:
Snap(13, 10) -- 10
Snap(17, 10) -- 20
Snap(712, 500) -- 500
The first argument is the number to round and the second is the number to round to.
Number = 17
To = 10
We first divide Number by To
17/10 = 1.7
Next we add .5 this will round instead of floor our number
1.7 + .5 = 2.2
Then we floor this number
math.floor(2.2) = 2
And finally we turn it back into its old size
2 * 10 = 20