Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Cinemachine: Keeping camera orientation when switching between freelook cameras

Discussion in 'Cinemachine' started by saint_george_23, Oct 20, 2020.

  1. saint_george_23

    saint_george_23

    Joined:
    Oct 22, 2015
    Posts:
    4
    Hello, I'm making a tactical game with a number of player-controlled agents. I want to be able to click on an agent and have the camera follow and look at that agent, but be able to orbit that agent. I've currently set each agent with their own freelook camera, and have a script that enables the selected agent's camera and disables the others. So far so good. What I'm struggling with is that each camera remembers its last position, so that when I switch, I often end up with the main camera facing a very different direction to that in which the player was last looking.

    What I want:

    Agent A is selected, Camera is south of A facing world north.
    Player selects agent B (who is north of A)
    Camera moves to just south of agent B and still faces world north.
    Player rotates camera to face south, and see agent A.
    Player selects agent A
    Camera moves to just north of agent A and still faces world south.

    What I'm getting

    Agent A is selected, Camera is south of A facing world north.
    Player selects agent B (who is north of A)
    Camera moves to just south of agent B and still faces world north.
    Player rotates camera to face south, and see agent A.
    Player selects agent A
    Camera moves to just south of agent A and faces world north.

    Is there a way to keep the camera facing the same way in world when I switch between the freelook cameras, or would I be better to have one free look camera and change its follow and lookat properties?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Probably the easiest approach would be to use a single FreeLook targeting an invisible gameobject, and put a custom script on the gameobject to lock position with the currently selected player.
     
  3. saint_george_23

    saint_george_23

    Joined:
    Oct 22, 2015
    Posts:
    4
    Thanks very much I'll give that a try.
     
  4. OJDee

    OJDee

    Joined:
    Feb 11, 2014
    Posts:
    64
    @Gregoryl I have the same question but in my case the camera switches from player character to different vehicles that have different freelook camera requirements.

    A single freelook wouldn’t work for this so any other suggestions please?
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Use multiple FreeLooks, one for each target, and activate/deactivate as necessary. CM Brain will blend. You can use InheritPosition on the FreeLooks.

    upload_2021-3-23_10-17-6.png
     
  6. OJDee

    OJDee

    Joined:
    Feb 11, 2014
    Posts:
    64
    Thanks a lot, that worked a treat!
     
    Gregoryl likes this.