I have a dynamic FOV and crouching script for my player which both use the Lerp function for smooth camera movement, but it only works for the increase in FOV and decrease in height. When the FOV and height return to normal, it just snaps back instantly rather than giving the smooth movement expected.
Crouching:
if (Input.GetKey(KeyCode.LeftControl))
{
characterController.height = Mathf.Lerp(characterController.height, 0.5f, 10f * Time.deltaTime);
canRun = false;
canJump = false;
walkingSpeed = 2f;
}
else
{
characterController.height = Mathf.Lerp(characterController.height, 2.0f, 10f * Time.deltaTime);
canRun = true;
canJump = true;
walkingSpeed = 4f;
}
FOV:
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D))
{
Camera.main.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView, 65f, 10f * Time.deltaTime);
}
else
{
Camera.main.fieldOfView = Mathf.Lerp(Camera.main.fieldOfView, 60f, 10f * Time.deltaTime);
}
I've looked online but no one seems to be having this issue and the code looks like it should work. (I am new to this so it's probably something really obvious)