Cinemachine Virtual Camera - Follow Offset Value Change Jitter

I’m using a cinemachine virtual camera. Follow and LookAt are both set to my player transform. The body of the camera is set to Transposer, binding mode: worldspace, with 0 dampening on x, y, and z.

In my code I’m changing the follow offset when when the camera can’t see the player at the normal follow offset:

CinemachineVirtualCamera cineCam;
CinemachineTransposer cineTransposer;
Transform player;

void Start()
{
    cineCam = this.GetComponent<CinemachineVirtualCamera>();
    cineTransposer = cineCam.GetCinemachineComponent<CinemachineTransposer>();
    player = GameObject.FindGameObjectWithTag(Tags.player).transform;
}

void Update()
{
      //funciton to raycast toward player from normal camera offset pos and see if it's viewable
      bool isNormalViewingPos = ViewingPosCheck(player.position + new Vector3(-15f, 40f, -15f));

      //if can't see player at normal viewing angle - move to secondary viewing angle
      if (!isNormalViewingPos)
      {
           cineTransposer.m_FollowOffset = new Vector3(-5f, 40f, -5f);
      }
      else
      {
            cineTransposer.m_FollowOffset = new Vector3(-15f, 40f, -15f);
      }
}

The issue is that the transition to the new follow offset looks really jumpy and not smooth. It’s looks as if it tries to transition from a different position to the new position rather than smoothly going from where it is to where the new values are.

Just realized the jumpy issue is caused from the camera’s rotation being slow to rotate while the offset snaps into place immediately. I then tried lerping the offset position to give the camera time to rotate and move smoothly. Now the camera is all stuttery when moving the offset in a Vector3.Lerp…

if (!isNormalViewingPos)
        {
            cineTransposer.m_FollowOffset = Vector3.Lerp(cineTransposer.m_FollowOffset, new Vector3(-5f, 40f, -5f), .02f);
        }
        else
        {
            cineTransposer.m_FollowOffset = Vector3.Lerp(cineTransposer.m_FollowOffset, new Vector3(-15f, 40f, -15f), .02f);
}

How would I animate this smoothly?

Changed my virtual camera’s “Anim” to Hard Look At in the inspector and the jitter went away… Not sure if that’s the right approach, but at least it’s working as expected now.

There are a couple of approaches that might be better:

  • Use 2 vcams, each with different offsets (and potentially other differences for added finesse), and activate the one you want, when you want it. Let the CM brain do a nice smooth transition for you.
  • Have an invisible object following the player at the desired offset, and use that as a follow target. When the offset suddenly changes, the Transposer damping on the vcam will smooth it out.
3 Likes

Very interesting. Thanks for the response Greg! I appreciate your help!