Improve movement and animation

I’m working on the basis of my next 2D project and as I’m new to Unity I’m having some problems.

One of them is with animation and movement. I leave a video for you to see:

https://vimeo.com/238557983

The change of animation with the movement is not completely fluid, for example, when moving upwards and then to the left the character continues to look briefly upwards, instead of immediately executing the animation of walking to the left.

This is the script I am using:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class playerController : MonoBehaviour
{
    private Animator animator;
    public float speed;
    // Use this for initialization
    void Start()
    {
        animator = this.GetComponent<Animator>();
    }
    // Update is called once per frame
    void Update()
    {
        var vertical = Input.GetAxis("Vertical");
        var horizontal = Input.GetAxis("Horizontal");
       
                  if (Input.GetKey (KeyCode.D))
         {
             transform.Translate(Vector2.right * speed);
         }
        
         if (Input.GetKey (KeyCode.A))
         {
             transform.Translate(-Vector2.right * speed);
         }
         if (Input.GetKey (KeyCode.W))
         {
             transform.Translate(Vector2.up * speed);
         }
         if (Input.GetKey (KeyCode.S))
         {
             transform.Translate(-Vector2.up * speed);
         }
        if (vertical > 0)
        {
            animator.SetInteger("Direction", 0);
        }
        else if (vertical < 0)
        {
            animator.SetInteger("Direction", 2);
        }
        else if (horizontal > 0)
        {
            animator.SetInteger("Direction", 1);
        }
        else if (horizontal < 0)
        {
            animator.SetInteger("Direction", 3);
        }

    }
}

Thanks.

Your script looks ok, not that Im an expert but…
I used this guys tutorials for my own game, it might be helpful…
Here is a link to one of his 2D RPG… Same style as your game

1 Like

My guess would be that either your input isn’t setup properly in the input manager or your animator transition isn’t setup properly for your sprite. Check to make sure you have a high acceleration and gravity set for your input and that the deadzone isn’t too big. Also check to make sure your animator’s transition to that state has exit time turned off and that the transition time is also set to 0.

1 Like

I finally solved it. It was the “Sensitivity” attribute in the Input Manager. By reducing the value I have managed to make the change of direction and animation immediate.

Thank you!