How to position a model on top of a part? (Different models & different sizes)

I have this piece of code that can move the model on top of a part but instead, it won’t go on top perfectly. I am using it to spawn random models to which they’re not the same size, so, it’s not dependent on a fixed number value to position itself on top of the part.

here’s the image:

the code:

local lvl = workspace.Levels;
local orientation, size = lvl.Level_1:GetBoundingBox();
local pp = workspace.ObstacleSpawnLocation
lvl.Level_1:MoveTo(pp.Position +, (pp.Size.Y + size.Y) / 2, 0));

As you can see some of its parts are still below the Part. which is the green one.

I think what might be the issue is the PrimaryPart
The head is tilted, so that could cause the boundingbox to be tilted as well

When I check my model’s PrimaryPart, it was the head and I noticed the tilted bounding box, then I changed it back to the HumanoidRootPart. The Boundingbox goes back into a perfectly oriented box, yet, still, it won’t go on top of the selected part.

OH, MY FREAKIN GOD. I think I know the reason why is it like that.

I’ve noticed the pivot location is not centered on the bounding box rather it goes to the model’s primary part by default.

As soon as I changed the location of the model’s pivot. the script also changed. I freakin hate this man… how do I change the location of the pivot directly in the center of the model now?

The easiest way is to ungroup the entire model and regroup it

Getting around with this problem seems pretty difficult, so, I just create a new part inside a model in order to set it as the new PrimaryPart. and used the TranslateBy() so that the orientation doesn’t get affected.

The code:

local lvl = workspace.Levels;
lvl.Level_1:TranslateBy(workspace.ObstacleSpawnLocation.CFrame.Position - lvl.Level_1.PrimaryPart.CFrame.Position);

If there is another better solution for this, please direct message me. Thank you.

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