making something align to a grid can be done like so:
local GridSize = 2 --The space between spots on the grid, so objects should be 2 studs apart.
function AlignVector3(Position) --Takes in any vector3
Position.X = math.floor(Position.X/GridSize)*GridSize --If Position.X == 3, then 3/2 = 1.5, and 1.5 floored (rounded down) = 1, then we multiply it by the gridsize to space it out.
Position.Y = math.floor(Position.Y/GridSize)*GridSize -- if it was 5, 5/2 = 2.5, rounded down to 2, 2*2 = 4
Position.Z = math.floor(Position.Z/GridSize)*GridSize --If it was 1, 1/2 = 0.5, rounded down to 0, 0*2 = 0.
return Position --Would have gone from Vector3(3, 5, 1) to Vector3(2, 4, 0) [xyz]
end
--//For example
print(AlignVector3(11, 5, 3)
console
10, 4, 2
If you want I can do a further walkthrough of why this works, and if you have any questions just ask.
lol, sorry to both you and @TheCursedSpud, I meant math.round. math.floor would reduce 3.99 to 3, so math.round would work better.
brain no worky.
But like others have said, a Vector3 can have each value rounded inside the Vector3.