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

How would I make a bigger grid to snap to?

Asked by
zblox164 531 Moderation Voter
6 years ago

So I managed to create a basic grid system where you move an object (Part or Model) to each stud. This is working but I want to know how to add to the grid. Instead of it being moved to each stud maybe every 4 or 5 studs.

Here is my code:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Part = workspace.Movement.PrimaryPart -- The model that I am moving

Mouse.Move:Connect(function()
    local PosX = math.ceil(Mouse.Hit.X) -- I also used math.floor()
    local PosY = 11.1 -- The current y position of the model's primaryPart
    local PosZ = math.ceil(Mouse.Hit.Z) -- I also used math.floor()

    -- Moving the model
    Part.Parent:MoveTo(Vector3.new(PosX, PosY, PosZ))
end)

I have tried added values to the Pos variables (lines 6-8) and it just creates a bigger problem. Thanks to who helps me!

1 answer

Log in to vote
1
Answered by
theCJarmy7 1293 Moderation Voter
6 years ago
Edited 6 years ago

You just need to round a little differently. It's basically the same as rounding the nearest multiple of 10.

local num = 17
local step = 10

print(math.floor(num / step + .5) * step)
--20

The logic for a different step is exactly the same, just divide, round, multiply.

0
Thanks zblox164 531 — 6y
Ad

Answer this question