How to prevent overlapping on placement system

  1. What do you want to achieve? I want to make sure models dont overlap on my placement system

  2. What is the issue? The problem is models overlap and I have no idea to fix it. (I have little to no knowledge about CFrame’s) This is what it looks like


    What i want it to look like:

Here is my code that shows the preview of model being placed if that helps:

mouse.Move:Connect(function()
	local snapped = Snap()
	model:SetPrimaryPartCFrame(CFrame.new(snapped[1], snapped[2], snapped[3]))
end)
  1. What solutions have you tried so far? I have tried :MoveTo function, although it technically prevents overlapping it prevents it by incrementing y axis until theres nothing overlapping, I am trying to prevent it in every axis(x y and z), I hope you guys get what I mean.
2 Likes

When your calculating positions for placement. You have to first consider that positions are based on the center point of the objects. Then you need to make adjustments based on the the sizes of each object. (and their rotations)

box.CFrame = chair.CFrame:ToWorldSpace(CFrame.new(0,box.Size.Y/2,0))

1 Like

Hello, is there a way to do this without having to specify both the chair and the box? I have changed the code you shared to look like this

mouse.Move:Connect(function()
		local snapped = Snap()
		model:PivotTo(CFrame.new(snapped[1], snapped[2], snapped[3]):ToWorldSpace(CFrame.new(0,model.Selection.Size.Y/2,0)))
	end)

It was working perfectly fine when i was placing the chair/crate on baseplate howewer when i tried to place the crate on the chair it was same as the first image on my post

I changed the code to do the same same thing for the x and z axis

model:PivotTo(CFrame.new(snapped[1], snapped[2], snapped[3]):ToWorldSpace(CFrame.new(0,model.Selection.Size.X/2,CFrame.new(0,model.Selection.Size.Y/2,CFrame.new(0,model.Selection.Size.Z/2)))

Then it started to behave really weird, Here is video of it:

Anyway, thank you for the code you posted I learned a lot of things thanks to it!

Edit: its the wrong video, i have now uploaded the correct one sorry for it

I assume your chair is single object then? You may want to break it down into multiple objects, then you can specify using the “SeatPart” of the chair. I’ll be honest I have zero experience with the Pivot Points.

Hello, PivotTo is pretty much same as SetPrimaryPartCFrame, I have used it because SetPrimaryPartCFrame was deprecated, my chair is a Model and it doesnt have a seat in it its just a model welded also the Selection part in it is a invisible anchored part that are represented by the green lines(I used selection box and set the adornee property to the selection part.

Ok. Then it sounds like the problem is with positioning offset due to the model. The center of the model is not the same as the center of the seat. Honestly I’m not sure at this point. I’m just trying to help you think through it.

Hello, I have tried setting primarypart of my crate to the selection part however it still didnt work showing same behavior the behavior im trying to get is like this:


(Its from the game whatever floats your boat) Look how at the video every axis they(somehow) prevent collision from happening

You can probably save the bounding box of the model to table or create object that will overlap the whole model and then you can use :GetTouchingParts() or you can use new OverlapParams to check if there isn’t any object in the certain region of the placed model bounding box.

I can check if there is a object overlapping with the model the thing is that I dont know what I can do with it, in other words I need to prevent them colliding at first place.

You can just run runservice loop and constantly check if it isn’t overlapping at this point you can use the method with overlapping part.

I am trying to prevent overlaps from happening at the first place, not to detect them. You should watch the last video I sent to see what I am talking about.

1 Like

I’ve seen it already but I don’t think there’s another way to do it, just give it a try and see.