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
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.