I have a movement script and I want my character to turn around and move the other way rather than moonwalk backwards (forward animation playing but backward movement). This script works, but sometimes the GetKeyUp won’t register and the character will be stuck facing the wrong way and you have to play with it to get them to face the right way again. Is there a simpler or better way to do this (maybe I should use an else instead of if)? Any input is welcome, and thanks in advance.
if (Input.GetKey (KeyCode.RightArrow)) {
animation.Play ("Allosaurus_Walk");
rigidbody.AddForce(Vector3.right *speedH);
}
if (Input.GetKeyUp (KeyCode.RightArrow))
{
animation.Stop ("Allosaurus_Walk");
animation.Play ("Allosaurus_Idle");
}
if (Input.GetKeyUp (KeyCode.LeftArrow))
{
animation.Stop ("Allosaurus_Walk");
animation.Play ("Allosaurus_Idle");
if (Input.GetKeyUp (KeyCode.LeftArrow))
{
transform.Rotate (0,180,0);
}
}
if (Input.GetKey (KeyCode.LeftArrow))
{
animation.Play ("Allosaurus_Walk");
rigidbody.AddForce(Vector3.left *speedH);
if (Input.GetKeyDown (KeyCode.LeftArrow))
{
transform.Rotate (0,180,0);
}
}