Get the exact centre of model in Viewport

I want to be able to make my model be perfectly centered in my viewport, so edges aren’t cut off. However this is what it currently looks like

Camera.CFrame = CFrame.new(Vector3.new(HouseClone:GetExtentsSize().X / 2, HouseClone:GetExtentsSize().Y / 2, HouseClone:GetExtentsSize().Z / 2))

It’s too far over to the right (the X axis) I did HouseClone:GetExtentsSize().X / 2 as I though that would position the camera in the middle of the model, but it ended up moving it over to the right

2 Likes

Couldn’t you just CFrame the model at an origin position (0, 0, 0) and set the camera to the same? Then apply rotation to get it to appear correctly.

1 Like

That wouldn’t center it. I have a PrimaryPart that gets placed in front of the door (for positioning purposes) and that’s not central. So setting everything to 0, 0, 0 would still be offset :confused:

1 Like

A recent update made it so that you can move the model while it’s in the viewport frame. Try moving the whole model until you get it to the desired position.

You have two ways of doing this:

Solution 1:

Create a part that is the size of the model. Call that something like TransparentPart.
Then you can cframe the camera like this:

Camera.CFrame = CFrame.new(HouseClone.TransparentPart.Position) * CFrame.new(0,0,HouseClone:GetExtentsSize().Z * 2)

Solution 2:
You can also use model:GetModelCFrame(), but it’s deprecated:

Camera.CFrame = CFrame.new(HouseClone:GetModelCFrame().Position) * CFrame.new(0,0,HouseClone:GetExtentsSize().Z * 2)

Demo:
test place.rbxl (136.0 KB)