Here's kind of what I'm looking to do:
I know I can use:
math.floor() and math.ceil() to round up and down. I also know I can create a rounding function:
local function round(number) return math.floor(number + 0.5) -- Rounds to the nearest whole number end
I would like to know how I could accomplish this with a grid size over 1x1. Thanks!
Simple solution!
*Divide mouse position by grid, add 0.5, round either up or down, and mutiply by grid (after rounding). You should be using a LocalScript
for this.
Example:
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local Part= workspace.Part local PosX, PosY, PosZ -- We will set these later local function Round(GridSize) PosX = math.floor(mouse.Hit.X / GridSize + 0.5) * GridSize -- Snaps PosY = 0.5 PosZ = math.floor(mouse.Hit.Z / GridSize + 0.5) * GridSize -- Snaps end local function Movement() mouse.TargetFilter = Part -- Ignores the model Round(2) -- Pass your grid size as an argument Part.Position = Vector3.new(PosX, PosY, PosZ) -- Positions end mouse.Move:Connect(Movement)
I KNOW I know that this is a year old but I just had to answer this. Hope this helps... if you see this.