In my game, there will be some objects, which, when the player clicks on one, the camera must adjust to focus on the entire object, such as zoom, so that the object occupies the entire screen, without clipping.
In this example, I have these 3 objects, each one with a different shape and size:
When the user clicks one, I want to calculate the camera.CFrame so the camera can FIT the entire object.
I know the default camera.FieldOfView = 70.
So I have just to calculate the DISTANCE from the camera to the selected object (It is similar to press F in the 3D editor to bring the selected object):
hey, how could i do this just so that the camera is looking straight down at the object? example:
for an object of size 20, 5, 1 the cameras cframe would be: (0, [calculated distance], 0) (0, -90, 0)
(i just noticed when i sent it that this was 4 years ago… im not expecting a reply anymore but ill leave this here :D)
You’re already given the distance here. It’s more of a radius so you can use that value for any camera angle.
let maxLength = 20 since you’ve specified your part size here.
To look straight down you could use CFrame.new() or CFrame.lookAt()
-- 1st parameter, the position of the camera
-- 2nd parameter, the position the camera aims at
Camera.CFrame = CFrame.new(targetPart.Position + Vector3.new(0,Distance, 0), targetPart.Position)
wait shi- … im stupid, i thought the whole thing was in brackets but im adding 5 to the math.tan so im deviding by five more than i should… yeah that would explain it
nvm, it still doesnt work