Forum rules - please read before posting.

How to "reset" First Person Camera Pitch on Scene Change?

edited October 2016 in Technical Q&A
Hello all,

I am working on a game, played via touch screen (Touch Controls Turning Only) and from a first person perspective.
My game contains two types of scenes so far:

  1. Panorama Scenes in which the player can turn around … and look up and down slightly. For this purpose I set "Constrain pitch-rotation (degrees)" to a sensible value (in my case of -7/+7), and everything works fine. From these Panorama Scenes, the player can switch to … 
  2. Still Scenes in which I do not want the player to move at all, so I change the Movement Method to "None" OnStart (and back to "First Person" on leaving the scene). This works fine, too. But:
If my player has "looked up" (Pitch: +7) in a Panorama Scene and then touches a hotspot to change to a Still Scene, the camera still "looks up" (Pitch: +7) in the Still Scene. I would like to reset the Pitch to 0 though.

As I cannot switch cameras in first person mode (except for cutscenes), I wonder if there is a way to reset the first person camera pitch via an action list action on Scene Switch. Is this possible? Or is there another way that I do not see?

Thank you.

Comments

  • edited October 2016
    ummm I'm not sure if there's an action to do that in AC, but it's pretty doable in scripting. The process itself isn't very hard but it may be confusing if you've never done much programming. ummm in the past there was a callback method to do this in unity similar to how Update() or Start() or Awake() work, but for some reason unity decided to drop it and made the process harder to understand for starters. Now you need to subscribe a method to an unity event. the code would be something like this:

    using UnityEngine.SceneManagement;
    using AC;
    ... // here goes your class name and stuff

    private GameCameraThirdPerson _cam;

    void Start()
    {
    //subscribe your method
    UnityEngine.SceneManagement.SceneManager.sceneLoaded += OnSceneSwitch;

    }

    void OnDestroy() // can use OnApplicationQuit in some cases
    {
    //unsubscribe your method
    UnityEngine.SceneManagement.SceneManager.sceneLoaded -= OnSceneSwitch;
    }

    protected void OnSceneSwitch(Scene scene, LoadSceneMode mode)
    {
    Debug.Log("Scene changed!");
    Debug.Log("Scene is: " + scene.name);
    //initialize the cameras
    _cam = FindObjectOfType<GameCameraThirdPerson>().GetComponent<GameCameraThirdPerson>();
    if (scene.name == "01-Home") // this is an example
    {
    //if it's scene "01-Home", lock pitch.
    _cam.pitchLock = RotationLock.Locked;
    }
    else
    {
    _cam.pitchLock = RotationLock.Limited; // could be Free, but you are limiting the pitch,no?
    }
    }
  • edited October 2016
    Ah, the above code is assuming you are using an AC third person camera as your player, but I think you can have a similar effect on regular cameras if you use:
     _cam.lockXRotAxis = true; // false to unlock it

    You'd just need to change the type of the camera like so:
    private GameCamera _cam;

    Also, you may want to "find" your camera by tag or name, so inside the OnSceneSwitch we made you could use:

    _cam = GameObject.FindGameObjectWithTag("your cam's tag").GetComponent<GameCamera>();
    _cam = GameObject.Find("camera Name").GetComponent<GameCamera>();
  • The pitch of a FirstPersonCamera can be set with the SetPitch function.  To reset the one on the player prefab, you can use this code:

    AC.KickStarter.player.GetComponentInChildren<FirstPersonCamera>().SetPitch (0f);

    Placing this line into the Run function of a custom Action would allow you to call it as part of your OnStart cutscene.
  • edited October 2016
    ah, I mostly use regular and third person cameras myself so I didn't even remember there was a first person camera component, sorry xD... Though, I prefer automation a bit more, but having it as a custom action is also an excellent idea too. 
  • edited October 2016
    Many thanks to both of you! 

    I got this to work with Chris' custom action!
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.