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!