Answered by
6 years ago Edited 6 years ago
Instead of using CFrame
to position the model, use Vector3
because it has collision detection (will make sure that the model/part doesn't overlap with another). In order to do this, you can use the method MoveTo()
. This means your code would look like this:
2 | local x = PlrMouse.Hit.p.X - PlrMouse.Hit.p.X % 5 + 2.5 |
3 | local y = PlrMouse.Hit.p.Y - PlrMouse.Hit.p.Y % 5 + 2.5 |
4 | local z = PlrMouse.Hit.p.Z - PlrMouse.Hit.p.Z % 5 + 2.5 |
6 | model:MoveTo(Vector 3. new(x , y , z)) |
I would also suggest you use a data structure of some sorts like a 3D array to represent the voxel based placement system you have so that you can represent each block that has been placed down and its corresponding state.