Search Unity

Stays in wrong animation when idle!! (gamesplusjames tutorial)

Discussion in 'Animation' started by ellibook7, Jan 25, 2019.

  1. ellibook7

    ellibook7

    Joined:
    Jan 25, 2019
    Posts:
    9
    Hi so im quite a beginner with unity so ive been following gamesplusjames 2d top down tutorial. Ive been doing the animations for my character and evrything works fine except the move right animation which gets stuck in the moving right animation when ive stopped. when i stop in any other direction this dosnt happen. The only error messages im getting are:
    No script asset for GameObjectSelectionItem. Check that the definition is in a file of the same name.

    But i do not think that has anything to do with my problem. Any help would be hugely appreciated and please explain so that i can understand as i'm not that familiar with the engine yet.

    :)

    Heres the script dor the movement:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerMovement : MonoBehaviour {

    public float moveSpeed;

    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;

    if(Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f )
    {
    transform.Translate (new Vector3 (Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f));
    playerMoving = true;
    lastMove = new Vector2(Input.GetAxisRaw("Horizontal"), 0f);
    }

    if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f)
    {
    transform.Translate(new Vector3(0f, Input.GetAxisRaw("Vertical") * moveSpeed * Time.deltaTime, 0f));
    playerMoving = true;
    lastMove = new Vector2(0f, Input.GetAxisRaw("Vertical"));
    }


    anim.SetFloat("MoveX", Input.GetAxisRaw("Horizontal"));
    anim.SetFloat("MoveY", Input.GetAxisRaw("Vertical"));
    anim.SetBool("PlayerMoving", playerMoving);
    anim.SetFloat("LastMoveX", lastMove.x);
    anim.SetFloat("LastMoveY", lastMove.y);
    }
    }
     
  2. ellibook7

    ellibook7

    Joined:
    Jan 25, 2019
    Posts:
    9
    Hi i found the problem, i had put the wrong animation in the right facing idle. I said i was a beginner