How do I make this position correctly?

Hello, I’m trying to make a building placement system. Currently, I have an issue where all of the buildings clip into the ground. It only has issues on the Y axis.

I’m pretty bad at math, so I’m not sure what I’m doing wrong. Here’s the piece of code that sets the model’s primarypart cframe using the mouse.

local function Round(to_round)
	local divided = to_round / GridStep
	local rounded = GridStep * math.floor(divided)
	return rounded
end

local Mouse = Player:GetMouse()
local PreviewObject = Folder:FindFirstChild(Button.Name):Clone()
local BoundingBox = PreviewObject:GetExtentsSize()
--this is in a renderstepped loop:
ObjectCFrame = CFrame.new(Round(Mouse.Hit.Position.X + (GridStep / 2)), (math.floor(Mouse.Hit.Position.Y + (BoundingBox.Y / 2))), Round(Mouse.Hit.Position.Z + (GridStep / 2)))

Any help would be much appreciated!

1 Like

The fix to this is very simple. You just need to put BoundingBox.Y/2 outside of the math.floor if I’m not mistaken, and add it to the math.floor value.

1 Like

Another solution that completely avoids this is setting the pivot of the models to be at their bottoms and using SetPivot on them instead of SetPrimaryPartCFrame.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.