Placement System Trouble

the result i want to achieve

  1. What do you want to achieve? Fix my Placement module

  2. What is the issue?

  3. What solutions have you tried so far? I have tried raycasting towards cliping object, but ended up with shaking model.

I want the model clamp out of the cliping object to prevent collision how much is possible, have you ever played lumber tycoon 2? It has this system, so when rotating an object it always stays out of the cliping object, thats what result I need.

line of code which provides the CFrame, Y_Bonus is a Y axis number to offset the object so it doesn’t clip with floor.

module.ToGrid = function(Pos, Normal, Y_Bonus)
	if Pos and Normal then
		Y_Bonus = Y_Bonus or 0
		local setPos = Pos + (Normal * (GridSize/2))
		local X,Y,Z = setPos.X,setPos.Y,setPos.Z
		X = math.floor(X/GridSize) * GridSize + GridSize/2
		Y = math.floor(Y/GridSize) * GridSize + GridSize/2 + Y_Bonus - GridSize/2
		Z = math.floor(Z/GridSize) * GridSize + GridSize/2
		return,Y,Z) + clipfix) * CFrame.fromOrientation(math.rad(RX), math.rad(RY), 0)

does anybody have an advice?


Looking at the video you shown, it looks like the clipping is sort of working. At the start when you already had a part down, when you clicked on top of it, you can see that it places the part on top of it instead of inside that existing part.


When you then try to place another part to the side of the object, your clipping is actually still working. If your clipping did not work, then it would have just placed the part inside of the part that has already been placed down. Your clipping point is based on the mouse position, which is the centre of the part you are trying to place down.

What your issue is that you only based the clipping on your mouse position but missed out on taking into account the size of the part you are placing down. If you base your clipping on the size of the part AND mouse position, then I think this would solve your problem.

the issue is that this game can have hitboxes with size like rectangles not only squares, and the clipping proof you had shown on the first screenshot is just basic anti-floor cliping which is Y position + Hitbox.Size.Y/2.

Fixed! Just had to manually type the position add on certain rotations and Normal Faces!