Help with Quaternion.Lerp

I know that questions to do with smooth transitions come up quite frequently, and I have read KurtDekkers helpful guide to them from here - SmoothMovement.cs · GitHub.

But even with that I cannot seem to get this to work, I would greatly appreciate if someone could tell me what I am doing wrong. What I am trying to achieve is when the player lets go of the aim button the crosshair smoothly returns to a postion parallel to the ground. During Start I set the position that I want the camera to return to, then in an “if” statement in Update I set the position that the camera has to move from and attempt to cause the transition. But nothing happens, I imagine my syntax is wrong, but I am not sure! Tahnk you in advance for any and all help! Here are the relevant parts of my code -

Quaternion startAngle;
Quaternion currentAngle;

void Start()
    {
        Quaternion startAngle = Quaternion.Euler(0, 0, 0);
    }

void Update()
    { if (Input.GetKeyUp(KeyCode.LeftShift))
                {currentAngle = CameraController.instance.target.transform.localRotation;
                 CameraController.instance.target.transform.localRotation = Quaternion.Lerp(currentAngle, startAngle, aimSpeed * Time.deltaTime);
}

Your code will only run for one frame, so it will look like it’s doing nothing

If you were to change the condition to something that runs every frame when the shift key is not being pressed, then it will allow you to at least test your code, though it will be trying to move to that rotation even when it’s already there.

if (!Input.GetKey(KeyCode.LeftShift))
1 Like

Thank you! This is a big help!