Animating the player character during movement

Hey everyone,

I’m designing a game akin to the olden SNES games, so a 2D grid in Pixel Art. Ive written a basic script that takes care of movement, and now Im trying to figure out how to animate characters in the animator.

Ive gotten to the point, where I have an idle state (facing the player), and when I press A or left, the character starts animating to the left. When the input stops, the characters stops animating. So far so good. But the other directions do not work, namely:

  • Up / W works as well, but not in the same playtest as left/A

  • Right/D and Down/S simply mirror the other two and don’t animate their own graphics, meaning if I press right, the character animates to the left.

Also, small side question, how do I move around in the animator. So far I can only zoom in and out which is really annoying. Thanks!

Hi @mandrayke , to answer your questions

  1. It look like your left and down axis are mirrored because of the Mathf.Abs methods that return an absolute value, ie. if input is -1 it will return 1, if it’s -0.5 it will return 0.5 etc.
    Instead, you could convert your code inside Update method to something like this:
void Update()
{
    animator.SetFloat("horizontal", Input.GetAxis("Horizontal));
    animator.SetFloat("vertical", Input.GetAxis("Vertical));
}

When you post your code in the forums, make sure you tag it properly
** Using code tags properly **

You can use middle mouse button, or press alt (option) key on your keyboard and then use left mouse button.
Hope this helps!