Hello everyone,
i just started using unity3d, or even using a game engine that far, about 3 days ago.
Now i came accross a minor problem i can’t figure out.
So far i have build a small 2d project, similar to the old zelda or secret of mana titles ![]()
I added a character with simple walking animations based on the direction i move the player.
I used the animator to create some simply animation states triggered by booleans for all 4 direction (Left, Right, Up, Down). These directions get updated every frame, and also will move the player in the desired direction.
So the player also has a controller script which does the job:
public class PlayerMovementController : MonoBehaviour
{
public float Speed = 10;
private Rigidbody2D _rigidbody2D;
private Animator _animator;
private void Start()
{
_rigidbody2D = GetComponent<Rigidbody2D>();
_animator = GetComponent<Animator>();
}
private void Update()
{
var horizontal = Input.GetAxisRaw("Horizontal");
var vertical = Input.GetAxisRaw("Vertical");
_animator.SetBool("IsWalkingUp", vertical > 0);
_animator.SetBool("IsWalkingDown", vertical < 0);
_animator.SetBool("IsWalkingLeft", horizontal < 0);
_animator.SetBool("IsWalkingRight", horizontal > 0);
var movement = new Vector2(horizontal, vertical);
_rigidbody2D.velocity = movement * Speed;
}
}
So the problem is:
If i move switch the input from left to right very fast (probably insight the same frame) the player character starts moving, but the animation lags behind and it looks like the player is doing a small moonwalk.
Is there a way to like interupt immediatly if i hit the inputkey or something like that?
Greetings cntx