r/UnityHelp • • Oct 19 '22

PROGRAMMING How to Move a Cinemachine Camera With Script, FOV and Follow Offset

I need help, I would like to know how do I animate the Cinemachine Virtual Camera in Follow Offset, I would like to change the y values. Well, FieldOfView can do it, because I want to use the FOV to do the ZoomOut and I wanted to use the Y to raise the camera a little. I am not getting it is working wrong. Note this camera has Player as Follow.

  1. CinemachineVirtualCamera _vCam;

  2. CinemachineTransposer cineTransposer;

  3. public float zoomSpeedFinish;

  4. public float X, Y, Z;

  5. public float PostT;

  6. private void Awake()

  7. {

  8. _vCam = GetComponent<CinemachineVirtualCamera>();

  9. cineTransposer = _vCam.GetCinemachineComponent<CinemachineTransposer>();

  10. }

  11. public void ZoomOutFinish()

  12. {

  13. _vCam.m_Lens.FieldOfView = Mathf.Lerp(_vCam.m_Lens.FieldOfView, 90, zoomSpeedFinish);

  14. cineTransposer.m_FollowOffset = Vector3.Lerp(cineTransposer.m_FollowOffset, new Vector3(X, Y, Z), PostT);

  15. }

3 Upvotes

1 comment sorted by

2

u/isitsou Oct 20 '22

As long as you don't iterate the ZoomOutFinish, Mathf.Lerp() won't work. This article explains everything in detail with great examples.

https://gamedevbeginner.com/the-right-way-to-lerp-in-unity-with-examples/

Hope it helps.