I know about rounding the position of the object to the nearest unit. I don't want to use that because it becomes inaccurate with different size objects.
I'm wondering how I would go about creating a grid placement systems that can be used on both models and individual parts.
If I have a part that is exactly 1 × Y × 1 studs, it would snap to the center of the nearest stud. That is possible using the rounding method.
If I have a part that is exactly 4 × Y × 4 studs, it would snap to the center of the nearest 4 studs. If I use the rounding method for this case, the part will snap to the nearest stud. That puts the center of my object at X.5 × Y × Z.5.
If someone could point me in the right direction here, I'd really appreciate it.
Thanks!
Found the solution!
local MousePos = Mouse.Hit.p local X = math.floor(MousePos.X) local Y = 0.5 local Z = math.floor(MousePos.Z) workspace.Part.CFrame = CFrame.new(X, Y, Z) local PartPos = workspace.Part.Position local newX = PartPos.X local newZ = PartPos.Z if (math.fmod(PartPos.X, 1) == 0) ~= true then local Decimal = math.fmod(PartPos.X, 1) local newX = PartPos.X + (1-Decimal) elseif (math.fmod(PartPos.Z, 1) == 0) ~= true then local Decimal = math.fmod(PartPos.Z, 1) local newZ = PartPos.Z + (1-Decimal) end PartPos = Vector3.new(newX, Y, newZ) workspace.Part.CFrame = CFrame.new(PartPos)