Getting center CFrame of model and scaling model with scripts?

I’m trying to center a model to the camera’s viewpoint and scale it down to use as 3D UI.

1 Like

You could have a part in the center and set it as the model’s PrimaryPart, then use Model:SetPrimaryPartCFrame() to move the model.

As for scaling, I think you’d need to get the offset of each part relevant to the center, then scale their size and offset from the center based on the scale.

local Scale = 0.5

Part.Size = Part.Size * Scale

local Offset = PrimaryPart.Position - Part.Position
Offset = Offset * Scale

Part.CFrame = CFrame.new(PrimaryPart.Position + Offset)
3 Likes

Thanks, that works for some of my static models, but what if the model is a character? and it’s Primary Part is it’s HumanoidRootPart so I can’t really change the Primary Part’s size and position.

You can change the HumanoidRootPart’s CFrame directly, but I’m not experienced in changing the scale of a character.

Yeah, I can change the CFrame directly, however I still need to find the centerpoint of the model in order to offset the model because the HumanoidRootPart of the character isn’t the center of the model.

Here’s an example, the outer blue part is the GetExtentsSize() of the model aligned to the HumanoidRootPart(Red Part), and the HumanoidRootPart isn’t the center of the model, ignoring the animation.
image

You could use :GetModelCFrame() I think it’s something along those lines, however keep in mind it is deprecated (Even though it works perfectly fine for most situations, yet there is no alternative unless you do many calculations) to get the centre point of the model.

1 Like

Thanks! This’ll do, and now for the character model scaling… Hmm

Couldn’t you just use the standard humanoid scaling method? Or are you ingame avatars not R15?

Custom characters, rigged differently.