Wednesday, December 25, 2024
spot_img

unity – Why does my object change its seen measurement once I rotate the simulator display?


Unity’s cameras preserve a relentless peak or vertical FoV – the portion of your scene that they see from the highest to the underside – and range solely their width / horizontal FoV because the side ratio of the display modifications.

In your first picture, the determine is about 50% the peak of the digicam’s view.

In your second picture, the determine remains to be about 50% the peak of the digicam’s view.

We will see this by overlaying your two instance photos:

Overlaid screenshots

So what’s occurred within the portrait mode view is that the areas to the left and proper have been cropped-out, whereas preserving the peak of the determine relative to the peak of the show.

That is the default as a result of it is often what we wish for 3D video games: gamers with widescreen screens ought to see extra on the left and proper, not much less on high and backside. For cellular video games, generally you need to customise it.

If you would like the alternative behaviour, sustaining the horizontal extent of the seen scene and cropping or extending the highest and backside, all it’s important to do is inform Unity that is what you need.

If you wish to scale to maintain the overall space of the seen scene fixed as a substitute, cropping a mixture of the width/peak as wanted, you could possibly modify the script like so:

// Items: m²
public float desiredSceneArea = 16*9;

void Replace() {
    // Items: pixels²
    float screenArea = Display.width * Display.peak;

    // Items: m/pixel
    float ratio = Mathf.Sqrt(desiredSceneArea / sceneArea);

    // Items: m
    float desiredHalfHeight = 0.5f * ratio * Display.peak;

    _camera.orthographicSize = desiredHalfHeight;
}

(That is utilizing replace since Unity nonetheless would not appear to reveal a easy window resize occasion – although you need to use the UI system and hook OnRectTransfromDimensionsChange to approximate that)

You may also make use of a UI Canvas, which provides a wide range of methods to manage how the canvas and its contents resize and rearrange themselves to suit on screens of various sizes. That is likely to be extra applicable in case you’re making an attempt to design an interface, quite than a view right into a world/scene.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles