Calculated Y Offset for Building System

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.
image
Current offset I have:

local EndPos = raycastresult.Position + Vector3.new(0,placeHolder:GetBoundingBox().Y/2,0)

Any help is greatly appreciated!

2 Likes

So do you want the wood to be flush on top of the white floor?

1 Like

Sorry for the misunderstanding, I am placing the rock. (The platform is just raised to test)

1 Like

If you want it to move to the rock but the move tools arent as precise either use F3X building plugin or set y axis/ x axis / z axis

1 Like

I have coded the placement system, I just need the Y offset to be exact, and to not be above what I am placing it on, or in.

1 Like

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

1 Like

The heights are indefinite sdsdfsdf

1 Like

How are you setting the position?

1 Like

Never seen that before. So the Y axis is NaN?

1 Like

I sent how, its the line of code

I meant are you doing Position, CFrame, Pivot, etc. The thing you sent is just a variable.

Position
sdsdfsdfsdf sdf sd fsdfsdf sdf

Have you tried GetExtentsSize instead of GetBoundingBox?

1 Like

No, I will try that right now.

1 Like

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.
image
Then just add the Mouses’ relative position and boom, done.

1 Like

If it’s just a part then you can use the Size property directly.

1 Like

Works better, still a small gap

I am making a placing system, so it would be better to use raycast. Your solution is very thought out though and I do appreciate it.

Mouse would be fine for a placing system, however it is better to use raycasts because Mouse is deprecated.

His code would work with raycasts…