Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How To Change Follow Mode Between Follow and LookAt

Discussion in 'Cinemachine' started by MrVandheer, Dec 28, 2020.

  1. MrVandheer

    MrVandheer

    Joined:
    Dec 28, 2020
    Posts:
    4
    Hi!
    I'm trying to union two camera follow mode like war3.
    e.g,when choose a role, the camera follow the role and move with right click. Set Follow to role can achieve that. And when mouse middle clicked,the camera need to look at the role and change FieldofView and distance to it. Set LookAt to role can achieve that.
    But i need to make sure after mouse middle click and camera finish moving,the follow mode change back to Follow mode. It would be really helpful if you could provide me with some examples to refer to. Thank you.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    The best way to do that is to set up 2 virtual cameras: one for standard Follow mode, and one for middle-click follow mode. Follow vcam is active by default. Middle-click vcam is inactive by default, but has a higher priority. When the middle button is pressed, activate the middle-click vcam. It will take control because of its higher priority. When middle button is released, deactivate the middle-click vcam and control will be returned to the Follow vcam.
     
    gaborkb likes this.
  3. MrVandheer

    MrVandheer

    Joined:
    Dec 28, 2020
    Posts:
    4
    Thanks for answering, but i still get questions. My code is like:
    if (Input.GetAxis("Mouse ScrollWheel") < 0){
    //Change CinemachineTransposer.offset, FieldOfView, set look at to follow, and Hard Look At mode will do the rest, will change rotation, distance to look at of the camera
    //The problem is that after these code, camera transform change is not happen yet, and when next update check other input, the camera transform is out of controll
    }
    else if (Math.Abs(Input.GetAxis("Vertical")) > 0.01f || Math.Abs(Input.GetAxis("Horizontal")) > 0.01f){
    //Set look at to null,and Change follow.transform
    }

    So, the left problem is, when set look at to follow and change offset, how can I listen the event camera transform changes complete so i can lock other input during those changes and release it after changes complete. Thx!
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    I don't understand what you're trying to do.

    Why not just set up 2 vcams as I described, and just do middleVcam.gameObject.SetActive() to activate/deactivate it? No need to worry about the transforms, they will take care of themselves automatically thanks to the CM behaviours.

    If you like, you can post a video and show the vcam inspectors to explain the problem a little better.
     
  5. MrVandheer

    MrVandheer

    Joined:
    Dec 28, 2020
    Posts:
    4
    Finally I success to make it work with your method!
    Sorry for my fuzzy desc, actually my problem is, when vertical input happens, I change the transform of Follow Target, and no matter I set LookAt to null, or set LookAtVCamera to inactive in the update(to change controller back to the Follow vcam), the LookAtVCamera still cause a rotation I cant controll like: file1 to file2.

    First I think when Transposer.Offset is changed, it will cost several update to final change camera pos, so I try to find a event or callback to catch the transitions done, but now I realize that if I set LookAtVCamera.Damping to 0, the transition will happen immediately.
    Thank you for your help again.
     

    Attached Files:

    Last edited: Dec 30, 2020