Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I stop the block going inside a block in my sandbox thing?

Asked by 6 years ago

Ive made a simple sandbox placing thing, but now I have a problem, how do I stop the green block going inside? https://gyazo.com/72e52379f548b38c93402b7ee99b074e This is my block placing script down below:

SetPrimaryPartCFrame(CFrame.new(PlrMouse.Hit.p.X-PlrMouse.Hit.p.X%5+2.5, PlrMouse.Hit.p.Y-PlrMouse.Hit.p.Y%5+2.5, PlrMouse.Hit.p.Z-PlrMouse.Hit.p.Z%5+2.5))

I added +2.5 to make it in the center of the mouse also.

1 answer

Log in to vote
0
Answered by
RayCurse 1518 Moderation Voter
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:

--Variables used for the sake of readability
local x = PlrMouse.Hit.p.X - PlrMouse.Hit.p.X % 5 + 2.5
local y = PlrMouse.Hit.p.Y - PlrMouse.Hit.p.Y % 5 + 2.5
local z = PlrMouse.Hit.p.Z - PlrMouse.Hit.p.Z % 5 + 2.5

model:MoveTo(Vector3.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.

Ad

Answer this question