Lerp jumping between two commands
Hello friends, I'm with a little issue here right now. I have a code on my character controller script that interact directly with the camera to make a "tilt" effect when the player moves sideward (A, D on keyboard). Is something like Quake did before. It's working perfectly, when you press A or D the camera tilts smoothely to left or right respectively. If you release A or D the camera returns to the position somoothely. But if I'm pressing A (the camera is tilted) and press B immediately, he looks to stop the smooth movement and jump directly to 0 (zero) position and begin the tilt to the right. This seems to cause a non-smooth movement on the camera. Exemple: (Press A: Camera tilts left from 0 to -2 gradually, if release A, the camera goes from -2 to 0 gradually and smoothely. But if player press B before the tilt reach -2 or 0 he goes directly to 0 to begin the right tilt). This is my code:
 public float leanAngle = 5f;
  
     float curAngle;
     float targetAngle;
     float angle;
  
     float maxRot = -45.0f;
     float rate = 2.0f;
  
 Update()
 {
     LeanCamera(Input.GetAxis("Horizontal"));
 }
  
 public void LeanCamera(float axis)
 {
         curAngle = playerView.transform.localEulerAngles.z;
         targetAngle = leanAngle - axis;
  
         if (axis == 0.0f)targetAngle = 0.0f;
  
         playerView.transform.localRotation = Quaternion.Lerp(playerView.transform.localRotation, Quaternion.Euler(playerView.transform.localRotation.x, playerView.transform.localRotation.y, axis * maxRot), Time.deltaTime * rate);
  
 }
 
               Please boys help me! D:
Your answer
 
             Follow this Question
Related Questions
Smooth rotate between changing rotations (already using Lerp, problems arise) 0 Answers
Hard coded rotation of child results in weird arc rotation when parent is rotated? 0 Answers
Object rotation lerp with acceleration 0 Answers
Rotating Camera around Player's X-axis while rotating Player around its Y-axis (using mouse input) 0 Answers