How Could I Make A Model Fit Inside A Viewportframe?

How could I make a model fit inside of a viewportframe without anything sticking out?

I haven’t tried any solutions so far because I don’t really know how to.

A picture of the viewportframe.

1 Like

Try sizing the model, frame, or move the camera a bit closer.

1 Like

But there’s more than one model

1 Like

https://gyazo.com/62078aeb06c3646e4a9e365ddc0d960e

1 Like

Well you could use the model scaling. Another way I can think of is to set an array of Udim2 or CFrame values for the camera or frame, then have it use the individual values for each model it goes on.

1 Like

Yeah, but is there a way to calculate where the camera should be?

1 Like

Probably, but I don’t exactly know how that’s gonna be done.

1 Like

You can calculate it knowing the FOV of the camera in the ViewportFrame and the height you want to include. Cameras on Roblox are always bound by their viewport height, dictated by the FOV, regardless of how wide the screen (or ViewportFrame) gets.

You can split the diagram on that page in half, imagining a right angles triangle with the acute angle at ½ your FOV (in this case ½ of 70 is 35°), the base is the length from your camera to the subject, and the height is ½ the height of the subject.

Using trigonometry find the unknown base length by

local base = 0.5 * subject.Size.Y / math.tan( 0.5 * camera.FieldOfView )

Set your camera CFrame to be base away from your subject (probably plus a stud or two margin) pointing back towards the subject.

4 Likes

I usually use GetBoundingBox() but I don’t know if that’s a good idea.

I forgot to say that I have already fixed the problem.