Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do you make this placement system work on a grid?

Asked by 5 years ago
Edited 5 years ago

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?

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

How it works

  • 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
0
I don't understand any of it, can you provide some explanation on it? YabaDabaD0O 505 — 5y
0
I added a little explanation. jermy1145 0 — 5y
0
If you post some of your placement code I might be able to help you implement it jermy1145 0 — 5y
Ad

Answer this question