Search Unity

X and Y axis follow cam

Discussion in 'Cinemachine' started by theshanergy, Feb 6, 2019.

  1. theshanergy

    theshanergy

    Joined:
    Nov 21, 2018
    Posts:
    9
    Is there any way to make a follow cam which follows the target velocity on both x and y axis while still allowing orbit aim? This seems like a really common use-case but for some reason none of the camera controllers I've tried seem to allow it. Imagine you have a third person character running up a steep mountain - since the camera always wants to center to 0 x axis rotation, you end up staring at the ground in front of you rather than looking upwards following the players movement. Same with running down hill, you can't see what's in front of the player. Is there any way to accomplish this with cinemachine?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    One way could be to write a custom CinemachineExtension that looks at the target's direction of movement and adjusts the aim offset accordingly: higher if going uphill, lower if going downhill.
     
  3. theshanergy

    theshanergy

    Joined:
    Nov 21, 2018
    Posts:
    9
    Wouldn't it have to be the body that moves, not the aim? I notice when I select 'Simple Follow With World Up' which is what I'm currently using, it disables the body selection of each of the rigs and locks them on Orbital Transposer. How would I go about increasing/decreasing the height of the rig in this case?
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    You could change the aim, or the body, dependiong on the effect you want. To change the body, you would have to adjust the FreeLook orbit heights.

    Another (perhaps better) option would be to have special invisible GameObject children of the target (one for LookAt, one for Follow - or they could be the same), and just move them up and down.
     
  5. theshanergy

    theshanergy

    Joined:
    Nov 21, 2018
    Posts:
    9
    On this note, I am actually using a special gameobject which I've called 'cameraTarget' which exists only to have all of my virtual cams follow the action - I've noticed something odd though, when I update this gameobject to follow one of my players by setting its transform.position to the transform.position of my target, for some reason the cinemachine cam becomes jittery, whereas if I target the player directly I don't get the jitter. Do you know why this would be? I'd rather not reparent the cameraTarget if I don't have to, though shouldn't just setting it's position be essentially the same thing? Why would I get jitter with the cameraTarget but not the real target?
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Jitters usually point to a clock mismatch: e.g. character moving on physics clock (fixedUpdate), but target transform updating on frame clock (update). Pick one clock and stick to it. Don't alter the transforms except on that clock.