How do i set a model Position/CFrame by it's exact center?

What is the issue?

I want to set a model position to the target position so that it aligns with the center of the model.
The problem is that :PivotTo() and MoveTo() move the model relatively to the primary part which won’t work for me. Here is an example:

(Green is the PrimaryPart and White outline is the target position)

Screenshot_3

Screenshot_2

The only solution that works is manually creating center parts or bounding box primary parts which sucks

code used for the demonstration

local TargetPart = workspace.TargetPart
local Model = script.Parent

Model:PivotTo(TargetPart.CFrame)

If I understand what you are asking I believe what you’d need to do is first calculate the difference between the PrimaryPart position and the model’s GetBoundingBox position and adjust the target by that much:

local TargetPart = workspace.TargetPart
local Model = script.Parent
local diff = Model:GetBoundingBox().p - Model.PrimaryPart.Position

Model:PivotTo(TargetPart.CFrame - diff)
1 Like

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