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

Reset freelook camera properly

Discussion in 'Cinemachine' started by mrCharli3, Jul 24, 2018.

  1. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    In my game my character with a freelook camera can die and respawn.
    However, the freelook camera does not reset behind the player as I would like it to, it just kind of flies from point of death to where the player respawns and then positions itself a bit randomly.

    Can this be fixed? :)
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Disable the FreeLook, warp the player to the spawn point, then re-enable the FreeLook.
    Or, you can try freeLook.PreviousStateIsValid = false;
     
  3. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    This does not seem to put the camera behind the player in "default" position
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    What is the binding mode of the FreeLook?
     
  5. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    Simple follow with world up.

    I realise this is the only binding mode that doesnt have the Heading definition. But if I do lock to target the whole thing is just un-usable, it follows the target too accurately and just jumps along with any bump or animation, makes me kinda seasick ^^ Simple follow with world up is the only one that is sort of smooth, even though some testers with 144 hz has complained about some jitters.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    You have to tune the damping settings on the FreeLook to get the smoothness you're looking for. There are a lot of settings, it's a bit of effort to get it just right, but it can be done. With the other binding modes too.

    With CM 2.2.0 there is a bug with SimpleFollow, relating to camera placement when the scene starts. This has been fixed in the latest release (2.2.7, available in preview). Probably you're tripping over it. A workaround would be to manually position the FreeLook, while it's disabled, at the same time as when you warp the character.

    Oh wait a minute, I just remembered something. There is an API that you can call when you warp a vcam's target, to warp the vcam along with it, bypassing the damping. It doesn't reset the vcam, it preserves the existing relationship. Maybe that will be useful to you. The API is vcam.OnTargetObjectWarped().
     
  7. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    Thanks, Ill try both :)
     
  8. piginhat

    piginhat

    Joined:
    Feb 17, 2016
    Posts:
    96
    Did this ever get resolved? I have the same problem and even if I disable the freelook, set PreviousStateIsValid to false, reset the transform of freelook then enable I still have the freelook remain in its old position?

    There must be a way to reset it to the starting parameters?.....surely?
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    The FreeLook will procedurally set its position based on the FollowTarget's position.
    Are you also moving the target before enabling the FreeLook?
    Are you resetting the FreeLook's axis values?
     
  10. piginhat

    piginhat

    Joined:
    Feb 17, 2016
    Posts:
    96
    when I select a new character, that always spawns in the centre of the scene I call a method attached to it like this:

    Code (csharp):
    1.  
    2.  public void ConnectCMFreeLook() {
    3.         // set look at transform
    4.         cmFreeLook.LookAt = cmFreeLookParameters.lookAtTransform;
    5.  
    6.         // set follow transform
    7.         cmFreeLook.Follow = cmFreeLookParameters.followTransform;
    8.        
    9.         // set height of top rig
    10.         cmFreeLook.m_Orbits[0].m_Height = cmFreeLookParameters.TopRig.x;
    11.  
    12.         // set radius of top rig
    13.         cmFreeLook.m_Orbits[0].m_Radius = cmFreeLookParameters.TopRig.y;
    14.  
    15.         // set height of middle rig
    16.         cmFreeLook.m_Orbits[1].m_Height = cmFreeLookParameters.MiddleRig.x;
    17.  
    18.         // set radius of middle rig
    19.         cmFreeLook.m_Orbits[1].m_Radius = cmFreeLookParameters.MiddleRig.y;
    20.  
    21.         // set height of bottom rig
    22.         cmFreeLook.m_Orbits[2].m_Height = cmFreeLookParameters.BottomRig.x;
    23.  
    24.         // set radius of bottom rig
    25.         cmFreeLook.m_Orbits[2].m_Radius = cmFreeLookParameters.BottomRig.y;
    26.     }
    27.  
    So I presumed as the cmFreeLook is being updated with the new characters parameters it would be correct?
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Yes, that should just zap the FreeLook to the new spot.

    Maybe there's something we're overlooking here. Would you be willing to export as a unitypackage a simple scene that shows this problem, and send it to me?
     
    piginhat likes this.
  12. piginhat

    piginhat

    Joined:
    Feb 17, 2016
    Posts:
    96

    Hi, I have sent you a PM with link to project
     
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    Thanks for the upload.

    When you retarget the FreeLook it does indeed zap to the right spot.

    You have the FreeLook set to World Space binding, which means that the X axis value is interpreted as a worldspace Y rotation, and not a rotation relative to the target. Since you have no code to change the axis value when you retarget, the FreeLook correctly just keeps the same value it happened to have at the time. You need to add these lines to your code to reset the axis values to your default settings:

    Code (CSharp):
    1.         // reset the POV to the default:
    2.         cmFreeLook.PreviousStateIsValid = false;
    3.         cmFreeLook.m_XAxis.Value = 0;
    4.         cmFreeLook.m_YAxis.Value = 0.5f;
    Also I noticed something in your scene. The FreeLook is parented to the main camera. Don't do that. Make them siblings. Why? Because the CM brain on the main camera sets its position according to the position of the vcam. If the vcam is a child of the main camera, then that act will move the vcam inappropriately. We don't want that.
     
    Last edited: Jul 16, 2019
    piginhat likes this.
  14. piginhat

    piginhat

    Joined:
    Feb 17, 2016
    Posts:
    96

    AWESOME! works perfect now, thanks :)

    I have moved the FreeLook out of the main camera as you suggest, I had only done it like this as this is how I was taught to use FreeLook in a tutorial.

    Thanks for your help :)
     
    Gregoryl likes this.
  15. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    If you can shoot me a link to the misinformed tutorial, I'll have a look at it.
     
  16. piginhat

    piginhat

    Joined:
    Feb 17, 2016
    Posts:
    96
    The instruction to child the freelook into the main camera is included in this Udemy course, Section 9, 5:04.

    I have made a comment in the course Q&A stating this thread.

    https://www.udemy.com/share/1011qaBEYcdl9QQX4=/
     
    Gregoryl likes this.
  17. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    Is there any way to capture when a freelook camera goes from standby to live? this would mean I only have to place the reset-code in one place, since this will always happen when transitioning to other cameras and then back to my freelook.

    Currently the freelook never resets properly when transitioning between cams and it get a bit annoying.
     
  18. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    I think this got answered in another thread, but for anyone else looking, you can hook into the vcam's OnCameraLive event:

    upload_2019-8-26_14-21-48.png