Hi,
I would like my character to go back to its original z rotation (straight) when I do not use the keyboard arrows anymore. But I think that, because there is still a value in the horizontal axis, the character continues to lean on the right or the left depending on which key i press. And then, when the value is at 0, it goes back to its rotation by default.
Would you know how to avoid this short time lapse and directly ask the character to go back to the original rotation in z?
Here is the code :
function Update () {
//rotate z keyboard
Debug.Log("horiz : "+Input.GetAxis("Horizontal"));
if ( Input.GetAxis("Horizontal") ){ /* leaning */
transform.Rotate( -Vector3.forward * 100 * Time.deltaTime * Input.GetAxis("Horizontal") );
transform.eulerAngles.z = ClampAngle(transform.eulerAngles.z, 10);
} else {
var m_lerp; /* returns to z rotation = 0 */
if (transform.eulerAngles.z < 180)
m_lerp = Mathf.Lerp(transform.eulerAngles.z, 0, 10 * Time.deltaTime);
else
m_lerp = Mathf.Lerp(transform.eulerAngles.z, 360, 10 * Time.deltaTime);
transform.eulerAngles.z = m_lerp;
}
Thanks