How to set a parts position exactly above another part

I know this is probably simple but why am I struggling to figure this out… lol. I’m trying to spawn in a model to be exactly above a part, so when it spawns in it isn’t floating or in the ground. Here’s my code so far:

local orientation, size = physicalNoob:GetBoundingBox()
local part = Instance.new("Part",workspace)
part.Anchored = true
part.Size = size
part.CFrame = workspace.Waypoints.Player.CFrame + Vector3.new(0,size.Y,0)

I get the bounding box of a model and then based off of that size I put it above the part I want it to be exaclty above. However, the part always appears to be floating. Here’s an image:

Could you not just increase the x value to whatever the part is you want to make exactly above the other part (increase it like by a few so that it not clipped into it and is more covering).

I could but the reason i’m using bounding boxes is the fact there’s going to be a lot of different models i’m wanting to teleport here. Ranging from height, and width so I need to figure out a way to set this exactly above the part without floating

Maybe look into :GetBoundingBox(). That should help you figure out the size of the model. Also, you could raycast directly down from above the model, and figure out the top of it from the hit position.

I tried raycasting but the same issue applied. Correct me if i’m wrong but this is what I used:

local orientation, size = physicalNoob:GetBoundingBox()
local part = Instance.new("Part",workspace)
part.Anchored = true
part.Size = size
part.CFrame = workspace.Waypoints.Player.CFrame + Vector3.new(0,size.Y,0)
local params = RaycastParams.new()
params.FilterDescendantsInstances = {workspace.ActiveNoobs:GetDescendants(), workspace.ActiveEnemies:GetDescendants()} 	params.FilterType = Enum.RaycastFilterType.Blacklist
local result = workspace:Raycast(part.Position, (-(part.CFrame.YVector) * 100 ), params)
		if result then
			local position = result.Position
			part.Position = part.Position - Vector3.new(0,result.Position.Y,0)
		end

You should probably use a whitelist and not a blacklist if that’s are you’re doing. Also, make sure you’re casting down. Is it erroring? or just not returning anything?

I’ll switch and use a whitelist just for the part I want the model to be above. I am casting down and it is properly working but it moves down only a tiny bit lol. The return Y position is 1 stud down even though the path is further down

What is the max distance on the raycast, and is it returning an instance?

I switched and used raycast.Distance instead of raycast.Position and now it’s halfway through the ground lol.

local position = result.Distance
part.Position = part.Position - Vector3.new(0,result.Distance,0)

the instance is returning as the part I want it to be above, so that’s working correctly. The distance is 2 studs now.

I do not know if this helps you, or if this is what you are asking for:

local part = -- [The part's location.]
local anotherPart = -- [The other part's location.]

part.Position = anotherPart.Position + Vector3.new(0, part.Size.Y / 2, 0)

If the part is a model, you’d type this:

local offset = Vector3.new(0, part:GetExtentsSize().Y / 2, 0)
part.Position = anotherPart.Position + offset
1 Like

Can you send the code? Because I’m not sure you’re doing this correctly. You should create a ray directly above the character, and then raycast down. But whitelist only members of the model.

1 Like

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