Hello everyone, I have looked into other posts on the DevForum about this issue, and none of them seem to be working, as you can see in the image below. I am trying to make an offset for a building system so that the model is not inside what I am placing it on. There are going to be surfaces higher than others, so it needs to work in regards to that.
Current offset I have:
local EndPos = raycastresult.Position + Vector3.new(0,placeHolder:GetBoundingBox().Y/2,0)
If you want to place it exactly on the floor you can try and keep putting approximate estimations of where the exact center (ex: like if the floor was at somewhere around 18 try 18.5 then try 18.4, etc) or you could just copy and paste the coordinates of the floor into the rocks properties
You don’t have to use raycasts to do this, just some simple CFrame math.
Here’s a really quick demo I made.
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local GhostPart = Instance.new("Part", workspace)
GhostPart.Transparency = .5
GhostPart.Size = Vector3.one
GhostPart.Anchored = true
Mouse.TargetFilter = GhostPart
Mouse.Move:Connect(function ()
if not Mouse.Target then
return
end
local MouseHit = Mouse.Hit
local Target = Mouse.Target
local MouseRelative = MouseHit:ToObjectSpace(Target.CFrame):Inverse()
GhostPart.Position = Target.Position + Vector3.new(0, GhostPart.Size.Y/2 + Target.Size.Y/2, 0) + (MouseRelative.Position * Vector3.new(1,0,1))
end)
The main thing to take away is that, since .Position will always give you the center of a part, you can just use each part’s size to get where the surfaces should be.
Then just add the Mouses’ relative position and boom, done.