Animation lastmove problem (Urgent; Game jam)

Hi so Iv’e been working on this game for a game jam and while setting up the animations i encountered this problem:


(The character doesn’t end in the direction they’re walking in when they stop)

Id love all the help i could get as I’m really pressed for time! :slight_smile:

PlayerController script:

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

public class Controller2D : MonoBehaviour {

   public float Speed;

   private Animator anim;

   private bool playerMoving;
   private Vector2 lastMove;

   // Use this for initialization
   void Start ()
   {
       anim = GetComponent<Animator>();
   }
  
   // Update is called once per frame
   void Update ()
   {
       playerMoving = false;

       float Dirx = Input.GetAxis("Horizontal") * Speed * Time.deltaTime;
       transform.position = new Vector2(transform.position.x + Dirx, transform.position.y);
       lastMove = new Vector2(Input.GetAxis("Horizontal"), 0f);

       if (Input.GetAxis("Horizontal") > 0)
       {
           playerMoving = true;
       }
       if (Input.GetAxis("Horizontal") < 0)
       {
           playerMoving = true;
       }

       anim.SetFloat("MoveX", Input.GetAxisRaw("Horizontal"));
       anim.SetBool("PlayerMoving", playerMoving);
       anim.SetFloat("LastMoveX", lastMove.x);
   }
}

Other helpful screenshots :smile:



IdleFace blend tree


PlayerMovement blend tree

i’d try something like having bool for isMovingRight,
and then setting that to true or false, only do that when Horizontal axis is not 0.
(and then use that for the blend tree or other parts)

currently it looks like your MoveX gets set to 0, so it always returns to that direction.

1 Like

Thank you for the reply :smile: I kinda fixed it by setting the idleface parameters to lastmovex but it still does a weird thing where when you stop when walking left the player turns first right then stops in the left direction! You have any clue what might be happening?

i think some value still sets it to 0, when no controller is used… and 0 is left.

Oh left is supposed to be -1 :open_mouth: Maybe thats the problem?