of     1   

Entelicon
#184110905Monday, February 22, 2016 12:23 AM GMT

How do I take an objects position and snap it to a 1 stud grid?
secretidagent
#184111395Monday, February 22, 2016 12:31 AM GMT

I am interested in knowing the same thing. -secretidagent
chimmihc
#184111489Monday, February 22, 2016 12:32 AM GMT

math.floor
secretidagent
#184111547Monday, February 22, 2016 12:33 AM GMT

@chimmihc So you get the players mouse hit position and then use math.floor on the position so that it stays on a 1-stud grid? -secretidagent
JarodOfOrbiter
#184111569Monday, February 22, 2016 12:34 AM GMT

Round it. #code local function RoundXToNearestY( X, Y ) return math.floor( X/Y + 0.5 )*Y end print( RoundXToNearestY( math.random()*100, 7 ) ) -- Round a random number between 1 and 100 to the nearest 7.
secretidagent
#184111684Monday, February 22, 2016 12:35 AM GMT

@Jared Cool. So you can change the grid size by giving it a different number (changing 7 to whatever grid snapping size you want)? -secretidagent
JarodOfOrbiter
#184111731Monday, February 22, 2016 12:36 AM GMT

If I did it right, then yeah. If I didn't, then it would currently round to the nearest 1/7 xD
fishguy100
#184113839Monday, February 22, 2016 1:07 AM GMT

local function alignToGrid(pos) local newPos = {} for _, axis in ipairs({"X", "Z"}) do local val = pos[axis] local rem = (val - 2) % 4 if rem < 2 then newPos[axis] = val - rem elseif rem >= 2 then newPos[axis] = val - rem + 4 end end return Vector3.new(newPos.X, 0, newPos.Z) end Idk if this works, made it off the top of my head :p

    of     1