I have a character in a top down game moving as per the motion of the mouse. How do I play the respective animation based on the direction, the character is facing at any moment ? Kindly note that my character sprite is not as if it is being seen from 90 degrees over its head, but as if the character is seen from its’ side. So, I don’t the game object to rotate, but just switch animations based on the direction it is facing.
I tried doing Mathf.Abs to check for Horizontal and Vertical axes but it didn’t work. Here is the code for my character movement based on the movement of the mouse.
private Vector3 mousePosition;
public float moveSpeed = 0.1f;
float speed = 1.0f;
void Start () {
Screen.showCursor = false;
}
void Update () {
if (Input.GetMouseButton(0)) {
mousePosition = Input.mousePosition;
mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
transform.position = Vector2.Lerp(transform.position, mousePosition, moveSpeed);
}
}
}