Prevent furniture from sinking into part

Currently I’m making a furniture placement system where on key pressed a clone of the model is created and follows the mouse position.
However the problem is the model seems to clip into parts pictured below.
I had initially played with the idea of adding the floors y size to the tables CFrame but that only raises the part by one stud, not to mention it wouldn’t work if the floor was very thick.


Local Script

ReplicatedStorage.FurniturePlacement.OnClientEvent:Connect(function(Table)
	CreatedFurniture = true
	mouse.Move:Connect(function()
		if CreatedFurniture then
			for i, v in pairs(Table:GetChildren()) do  -- Table is the furniture model
				if v.Name ~= "GridPart" then  -- Gridpart is the primary part
					v.Transparency = 0
				end
			end
			SnapFurniture()	-- "Snaps" furniture to grid
			mouse.TargetFilter = Table
			local floor = mouse.Target
			Table:SetPrimaryPartCFrame(CFrame.new(Vector3.new(posX, posY, posZ)))	-- Pos values from SnapFurniture function
		end
	end)
end)
1 Like

raycast down from each table leg to get the height of the table. Also do a raycast from each corner to the center to see if’s intersecting anything or do #hitbox:GetTouchingParts()>ThatAmountOfPartsThatWouldNormallyBeInTheHitBox

Okay, but you haven’t elaborated on how this could stop the item from clipping into the part.
E.g: What would I do afterwards?

1 Like

You do checks to see if the part is clipping or if it’s grounded. If it’s clipping don’t let them place it. If it’s not grounded move it up or down accordingly.

You’ll need to find the height of the model. Usually what I do is have a transparent part that covers the entire model and acts as its collision box, and then you can find the height by simply finding the Y component of this parts size. Then, you just add half of this height to the Y component of your CFrame. That would be done in this part:

Table:SetPrimaryPartCFrame(CFrame.new(Vector3.new(posX, posY + sizeY/2, posZ)))
1 Like