public void SetDirection() { actualPosition = this.transform.position; Vector3 delta = actualPosition - previousPosition; float x = delta.x; float y = delta.z; float angle = Mathf.Atan2(y, x) * (180 / Mathf.PI); if (angle > 0 && angle < 45) { mySpriteDirection = spriteDirection.Right; myAnimator.SetInteger("direction", 4); } if (angle > 45 && angle < 135) { mySpriteDirection = spriteDirection.Up; myAnimator.SetInteger("direction", 1); } if (angle > 135 && angle < 225) { mySpriteDirection = spriteDirection.Left; myAnimator.SetInteger("direction", 2); } if (angle < 0 && angle > -45) { mySpriteDirection = spriteDirection.Right; myAnimator.SetInteger("direction", 4); } if (angle < -45 && angle > -135) { mySpriteDirection = spriteDirection.Down; myAnimator.SetInteger("direction", 3); } if (angle < -135 && angle > -225) { mySpriteDirection = spriteDirection.Left; myAnimator.SetInteger("direction", 2); } previousPosition = this.transform.position; }
public void SetDirection() { actualPosition = this.transform.position; Vector3 delta = actualPosition - previousPosition; float x = delta.x; float y = delta.z; float angle = Mathf.Atan2(y, x) * (180 / Mathf.PI); if(angle > 0 && angle < 45) { mySpriteDirection = spriteDirection.Right; myAnimator.SetInteger ("direction", 4); } if(angle > 45 && angle < 135) { mySpriteDirection = spriteDirection.Up; myAnimator.SetInteger ("direction", 1); } if(angle > 135 && angle < 225) { mySpriteDirection = spriteDirection.Left; myAnimator.SetInteger ("direction", 2); } if(angle < 0 && angle > -45) { mySpriteDirection = spriteDirection.Right; myAnimator.SetInteger ("direction", 4); } if(angle < -45 && angle > -135) { mySpriteDirection = spriteDirection.Down; myAnimator.SetInteger ("direction", 3); } if(angle < -135 && angle > -225) { mySpriteDirection = spriteDirection.Left; myAnimator.SetInteger ("direction", 2); } previousPosition = this.transform.position; }