How to calculate where to position the camera based on character and screen size

How can I calculate where to position the camera based on the character size but more importantly screen size

My current code uses the same position for all the characters and screen sizes here’s the results;

Code
Camera.CameraType = Enum.CameraType.Scriptable
Camera.FieldOfView = 60
Camera.CFrame = HumanoidRootPart.CFrame * CFrame.Angles(0,math.rad(180),0) * CFrame_New(2.5, .5, 6.5)--workspace.CameraPart.CFrame

Too much to the right

Too low and the bunny ears are cut off

A bit too much to the left

The character is too big and the wings are cut off


I hope the images provided explains what I am trying to achieve, feel free to ask questions.

1 Like

You might be able to use GetExtentsSize to improve how far to zoom out.

2 Likes

Thank you! :+1:


local ExtentsSize = Cha:GetExtentsSize()
Camera.CameraType = Enum.CameraType.Scriptable
Camera.FieldOfView = 60
Camera.CFrame = HumanoidRootPart.CFrame * CFrame.Angles(0,math.rad(180),0) * CFrame_New(2.5+(ExtentsSize.X/10), .5, 6.5+(ExtentsSize.Z/2))

Great now I need a good ratio and some math stuff + figure out how to calculate for screen sizes.

1 Like

How did you solve this for different screen sizes?

You can use workspace.CurrentCamera.ViewportSize

Obviously. To implement workspace.CurrentCamera.ViewportSize, you’ll need a comprehensive understanding of what you’re going to do with it, which, unsurprisingly, you haven’t provided. You see, merely stating the obvious without diving into the intricacies is rather unhelpful, wouldn’t you agree?

How is this 4 years old?! Jesus.

well sorry for at least replying to a 4 year old bump reply