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!
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.