[solved] Issue With Animation To The Right Showing - 2d Top Down

Ok, I want to start by saying that I’m extremely new to all of this. I have pieced things together that I have found online so the way things are setup might not be the best way to do it. However I am having an issue with my animation for walking to the right (MoveRight) doesn’t work. This is for a top down 2d game. Here is what my animator looks like. I hope it’s done correctly please be kind if it’s not :(.

Also here is the coding that I pieced together to get it working.
It does properly change from the idle animation and back on all but going right and at that point it continues showing the idle animation.
I have went as far as to change the keys associated to the animation changes and deleting and making the animation again.
I would be so confused as to why it isn’t working if it wasn’t for the fact that I setup the left and then copied and pasted the rest changing the key and animation associated to it.

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

public class PlayerAnimation : MonoBehaviour
{

    public Animator anim;
    public float maxSpeed = 7;

    // Start is called before the first frame update
    void Start()
    {
        anim = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            anim.SetBool("MoveLeft", true);
            anim.SetBool("MoveRight", false);
            anim.SetBool("MoveUp", false);
            anim.SetBool("MoveDown", false);
            anim.SetBool("Idle", false);
        }
        if(Input.GetKeyUp(KeyCode.LeftArrow))
        {
            anim.SetBool("MoveLeft", false);
            anim.SetBool("Idle", true);
        }
        if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            anim.SetBool("MoveRight", true);
            anim.SetBool("MoveUp", false);
            anim.SetBool("MoveDown", false);
            anim.SetBool("MoveLeft", false);
            anim.SetBool("Idle", false);
        }
        if (Input.GetKeyUp(KeyCode.RightArrow))
        {
            anim.SetBool("MoveRight", false);
            anim.SetBool("Idle", true);
        }
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            anim.SetBool("MoveUp", true);
            anim.SetBool("MoveRight", false);
            anim.SetBool("MoveDown", false);
            anim.SetBool("MoveLeft", false);
            anim.SetBool("Idle", false);
        }
        if (Input.GetKeyUp(KeyCode.UpArrow))
        {
            anim.SetBool("MoveUp", false);
            anim.SetBool("Idle", true);
        }
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            anim.SetBool("MoveDown", true);
            anim.SetBool("MoveRight", false);
            anim.SetBool("MoveUp", false);
            anim.SetBool("MoveLeft", false);
            anim.SetBool("Idle", false);
        }
        if (Input.GetKeyUp(KeyCode.DownArrow))
        {
            anim.SetBool("MoveDown", false);
            anim.SetBool("Idle", true);
        }
    }

    void FixedUpdate()
    {

        if (Input.GetKey(KeyCode.UpArrow))
        {
            transform.Translate(Vector3.up * Time.deltaTime, Camera.main.transform);
        }
        else if (Input.GetKey(KeyCode.DownArrow))
        {
            transform.Translate(Vector3.down * Time.deltaTime, Camera.main.transform);
        }
        else if (Input.GetKey(KeyCode.RightArrow))
        {
            transform.Translate(Vector3.right * Time.deltaTime, Camera.main.transform);
        }
        else if (Input.GetKey(KeyCode.LeftArrow))
        {
            transform.Translate(Vector3.left * Time.deltaTime, Camera.main.transform);
        }
    }
}

EDIT: So I noticed this when opening the file I got the following errors in the Console

Controller ‘Player’: Transition ‘’ in state ‘MoveDown’ uses parameter ‘MoveRight’ which is not compatible with condition type.

It shows this for all states. up, down, left, and idle

I’m not sure what I should be looking at to fix this. Any suggestions?

Anyone at all?

Hey man,

First thing I would do. Split your view in two. Animator on one side, game view on the second.
Press play and click your animating object from the hierarchy to show the animator state.

Now… When you move right do you se the MoveRight bool trigger in the animator window?
If not then your code does not trigger the animator properly.

If you do see the animator bool trigger, but the animation stays on something else. Then it Must your animation transitions that’s the issue. Check every arrow that leads to your MoveRight anim and make sure the condition is your move right bool.

You may have simply just left the condition out, or have the wrong condition.

Well in an attempt to possibly fix the issue I remade the setup of the states. Here is a screenshot to hopefully show what is happening. As far as I can tell everything is setup properly.

That screen shot shows, bool is true, the blue line to the move right anim indicates it is about to start playing the move right anim. So what’s the problem, is it still not playing the animation? Maybe your move right anim is actually the sprites for a different animation.

Btw, I just noticed that you have everything revolving around the Idle animation. So if your going left, and you want to go another direction you first have to pass through idle, that’s not good :frowning:

I recommend you set your Animator up in a kind of start formation, with “Any State” in the middle. So from any state you go to Idle,Left,Right,Up,Down,Etc…

Then just have one condition from any state that checks if every move direction bool is false, then go to idle.

It is showing blue because that is what I have selected so you can see how it is set up. I’ll try your suggestion with the any state.

Just wanted to give an update that it started working when I implemented the any state.