Running animtation dosnt stop

Hi,

I am on the 2D rpg course and on the section regarding animating the player. I have done what the instructor said but the running animator keeps going and it doesn’t switch to the idle animation.
Could someone help please?

Hi Blake, Paste in the script you use for moving the player. Maybe some screen shots of the inspector for the player and the animator. With out more detail, it is impossible to answer your question.

1 Like

Take a look at the transitions between Idle and Running and back again. This sounds like it’s possible that you have Exit time unchecked, but you do not have a condition set to switch back to idle.

1 Like

Thanks for the help guys.

Here’s the code. Its just the code from the first couple sections of the new 2D RPG course. Obviously something is stopping the animation from returning to Idle but as far as I can see Ive copied the lecturer exactly. Ill post screen shots below.

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class PlayerController : MonoBehaviour

{

[SerializeField] private float moveSpeed = 1f;

private PlayerControls playerControls;

private Vector2 movement;

private Rigidbody2D rb;

private Animator myAnimator;

private SpriteRenderer mySpriteRenderer;

private void Awake() {

    playerControls = new PlayerControls();

    rb = GetComponent <Rigidbody2D>();

    myAnimator = GetComponent <Animator>();

    mySpriteRenderer = GetComponent<SpriteRenderer>();

}

private void OnEnable() {

    playerControls.Enable();

   

}

private void Update(){

    PlayerInput();

}

private void FixedUpdate() {

    AdjustPlayerFacingDirection();

    Move();

}

private void PlayerInput(){

    movement = playerControls.Movement.Moves.ReadValue<Vector2>();

    myAnimator.SetFloat("movex", movement.x);

    myAnimator.SetFloat("movey", movement.y);

   

}

private void Move(){

    rb.MovePosition(rb.position + movement * (moveSpeed *Time.fixedDeltaTime));

}

private void AdjustPlayerFacingDirection(){

    Vector3 mousPos = Input.mousePosition;

    Vector3 playerScreenPoint = Camera.main.WorldToScreenPoint(transform.position);

    if (mousPos.x < playerScreenPoint.x) {

        mySpriteRenderer.flipX = true;

    } else {

        mySpriteRenderer.flipX = false;

    }

}

}


Ok so…

I was mucking around with it while waiting on replies.

Then the idle animation stopped working completely. So I deleted the animation states and remade them and guess what? Now it functions as in the video. Doh! :exploding_head: But i still have no idea why…they were the same as far as I can tell. I just copied the same instructions and this time it works :man_shrugging:

1 Like

That happens a lot more than you might think. One of the things that can make helping tricky is that sometimes Unity just bugs out with something and we keep looking for reasons of what went wrong.

Glad you got that sorted!

1 Like

I have a love/hate relationship with Unity. :rofl:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms