Forum rules - please read before posting.
Tech questions during the weekend? Drop in on the community Discord channel!

Set certain values of First Person Camera depending on variable value

edited November 2019 in Technical Q&A

Hello all,

in a first person mobile game I am working on, some scenes consist purely of 360 photo panoramas, in which the player can look around and slightly up and down. In order to keep the margins of these photos out of sight, I use the pitch constraint of the player’s camera. Unfortunately, as we all know, there are different screen aspect ratios on mobile devices; while a pitch constraint setting works fine for a contemporary 2:1 iPhone Screen, on a 4:3 iPad screen the same setting does not and reveals these margins.

My idea was to catch the device type and/or screen aspect ratio via a script, save that information into a variable, and then set the first person camera settings accordingly. I think that three or four different settings would do.

As all game cameras except for the nested child of the player prefab get ignored, it occurred to me that I would like to have three of four camera children on my first person player prefab with different camera settings, and when the scene loads, the „right“ camera child gets activated depending on the var‘s value. Is that “allowed” Or even possible?

I prefer to use “physical cameras” by the way, so actually I would not only pre-set different pitch constraint settings in AC’s First Person Camera (script), but also different focal lengths and maybe even sensor types in Unity’s camera component.


  • Do note that if you enforce an aspect ratio in AC's Settings Manager, then black bars will be displayed if played on a screen with a differing ratio - this can be used to ensure that all devices behave the same.

    For something more dynamic, you can indeed read the current ratio and update your cameras as necessary. You wouldn't have to create a different camera for each one, though - just modify the values of one.

    For example, in a custom script attached to the FirstPersonCamera GameObject:

    void Start ()
        AC.FirstPersonCamera fpCam = GetComponent <AC.FirstPersonCamera>();
        float aspectRatio = Screen.width / Screen.height;
        if (Mathf.Approximately (2f))
            // 2:1
            fpCam.maxY = 20f; // Or whatever
        else if (Mathf.Approximately (4f / 3f))
            // 4:3
            fpCam.maxY = 20f; // Or whatever
        // Set the minimum pitch to the inverse of the maximum
        fpCam.minY = -fpCam.maxY;

    You could similarly use this trick to update the values of the FirstPersonCamera's Camera component, but I'd recommend controlling the maxY value to begin with.

  • This is working beautifully - thanks, Chris!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.