Search Unity

Animation lastmove problem (Urgent; Game jam)

Discussion in 'Animation' started by ellibook7, Mar 16, 2019.

  1. ellibook7

    ellibook7

    Joined:
    Jan 25, 2019
    Posts:
    9
    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! :)



    PlayerController script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Controller2D : MonoBehaviour {
    6.  
    7.    public float Speed;
    8.  
    9.    private Animator anim;
    10.  
    11.    private bool playerMoving;
    12.    private Vector2 lastMove;
    13.  
    14.    // Use this for initialization
    15.    void Start ()
    16.    {
    17.        anim = GetComponent<Animator>();
    18.    }
    19.  
    20.    // Update is called once per frame
    21.    void Update ()
    22.    {
    23.        playerMoving = false;
    24.  
    25.        float Dirx = Input.GetAxis("Horizontal") * Speed * Time.deltaTime;
    26.        transform.position = new Vector2(transform.position.x + Dirx, transform.position.y);
    27.        lastMove = new Vector2(Input.GetAxis("Horizontal"), 0f);
    28.  
    29.        if (Input.GetAxis("Horizontal") > 0)
    30.        {
    31.            playerMoving = true;
    32.        }
    33.        if (Input.GetAxis("Horizontal") < 0)
    34.        {
    35.            playerMoving = true;
    36.        }
    37.  
    38.        anim.SetFloat("MoveX", Input.GetAxisRaw("Horizontal"));
    39.        anim.SetBool("PlayerMoving", playerMoving);
    40.        anim.SetFloat("LastMoveX", lastMove.x);
    41.    }
    42. }
    Other helpful screenshots :D





    IdleFace blend tree


    PlayerMovement blend tree
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,433
    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.
     
    Last edited: Mar 16, 2019
    ellibook7 likes this.
  3. ellibook7

    ellibook7

    Joined:
    Jan 25, 2019
    Posts:
    9
    Thank you for the reply :D 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?
     
  4. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,433
    i think some value still sets it to 0, when no controller is used.. and 0 is left.
     
  5. ellibook7

    ellibook7

    Joined:
    Jan 25, 2019
    Posts:
    9
    Oh left is supposed to be -1 :O Maybe thats the problem?