Search Unity

Freelook camera stuck in the same rotation as lookat/follow started in

Discussion in 'Cinemachine' started by mrCharli3, Aug 23, 2019.

  1. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    If I enable my freelook camera when my follow/lookat is rotated, say he is standing on uneven ground and his rotation transform is [0, 0, 27], then the camera will correctly adapt and also rotate. However, it is then stuck in that rotation, and does not go back to [0, 0, 0] when the floow/lookat does, so it is super disorienting running around with a tilted camera.



     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    It's because of this:

    upload_2019-8-26_11-4-51.png

    Set it to LockToTarget instead.
     
  3. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    Ah I see I was worried that was why. This mode really doesnt work for me since the animations I use on the character can be a bit wobbly, so the camera wobbles too much.

    Maybe I can just add a script to the camera that will set Z rotation to 0 if its not 0.
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    What if you just added more angular damping on roll?
     
  5. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    I would have to put Pitch, yaw and roll to about 10, but that causes some other issues where the camera keeps panning after stopping due to too much smoothing.

    This is not something I expect Cinemachine to fix since its due to poor animation work. Is there any way to access the Z rotation? Cant find it, and editing it in editor does nothing.
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    You can't manually change the vcam's transform, as it is controlled by the vcam script which will always overwrite what you put.

    How about using the LockToTargetWithWorldUp binding mode?
     
  7. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    I've tried them all with all types of damping, the only one that feels good is Lock to target on assign =/ It requires so much damping that the camera literally does half a lap around the character before stopping when Im turning.

    So there is no way to manipulate the vcams z axis? Or just a setting that locks the z rotation at 0.
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    LockToTargetWithWorldUp locks the Z rotation. I'm not really sure what behaviour you're looking for when the character is tilted. Maybe you can have a dummy game object that tracks the target but orients itself the way you want, and use that as a vcam target.
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    You could also try writing a custom CinemachineExtension to rotate the vcam.
     
  10. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    I want it to behave exactly like Lock to target on assign, but without moving on the z axis.
    That is a great idea for the dummy game object, Ill try that.
     
  11. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    I sent you an example scene if you want to see what I mean. In the meantime, I added this script to the camera target (target is a child object at the center of the player model). And seems to solve it :)


    private void LateUpdate()
    {
    var rotationVector = transform.rotation.eulerAngles;
    rotationVector.z = 0;
    transform.rotation = Quaternion.Euler(rotationVector);
    }
     
    Gregoryl likes this.
  12. mrCharli3

    mrCharli3

    Joined:
    Mar 22, 2017
    Posts:
    976
    Is there any docs on how to do this?

    Unfortunately my solution posted above does not always work... When transitioning from one camera back to my freelook cam the z value is still not 0 for some reason, which makes no sense to me. I do this to my camera target so Z should always be world 0, independent of the parent (my players) rotation.

    Code (CSharp):
    1. private void Update()
    2.     {
    3.         Vector3 parentSpaceUp = transform.parent.gameObject.transform.InverseTransformDirection(Vector3.up);
    4.         transform.localRotation = Quaternion.LookRotation(Vector3.forward, parentSpaceUp);
    5.     }
     
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    The best docs on CinemachineExtension are the source files for the extensions that ship with Cinemachine. Your extension needs to set state.RawOrintation to have zero Z rotation.

    As for why your dummy child object solution is not working, I really don't know. Can you prove that the invisible game object really has 0 Z rotation, say by attaching a cube or some shape to it so that it becomes visible?