private void SetMovementAnimation() { // If the player is moving at all if (verticalInput > 0 || verticalInput < 0 || horizontalInput > 0 || horizontalInput < 0) { // Set the animation to run playerAnim.Run(); } // Otherwise else { // Set the animation to idle playerAnim.Idle(); } }
IEnumerator Move() { while (canMove) { //calculate new transform.position Vector3 newPos = Vector3.Normalize(new Vector3(InputManager.instance.GetHorizontal(), 0, InputManager.instance.GetVertical())) * speed; //print (newPos); //rotate character if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) { transform.rotation = Quaternion.LookRotation(newPos); } else { playerAnim.Idle(); } //move to new position rigidbody.AddForce(newPos); if (rigidbody.velocity.magnitude > 0.1) { playerAnim.Walk(); } if (speed > baseSpeed) { playerAnim.Run(); } //Resets velocity to 0 each frame so character doesn't slide around rigidbody.velocity = new Vector3(0, rigidbody.velocity.y, 0); yield return(null); } }