Play walk animation, based on object direction

Hello I’ve been at my computer for hours on end, trying to set a bool true in the animator based on the player movement direction.

bools:
WalkForward
WalkLeft
WalkRight
WalkBackwards

I’m doing this for mobile so WASD won’t really help, I can’t find anything at all to help me, everything I’ve seen and tried with Vector3 just gets the player’s movement, based on world space. Not the movement direction the actual player object itself is moving in. I really need help with this, I can’t sit here any longer trying to find answers :frowning:

I have a script in C# but I move forward, depending on the direction I’m facing, both the forward and left bool will enable. Here is my code, I greatly appreciate any help I can get at all.

public class MoveDir : MonoBehaviour
{

public Transform Player;

Vector3 oldPos;
Quaternion oldRot;

public bool isMovingForward;
public bool isMovingLeft;
public bool isMovingRight;
public bool isMovingBackwards;

void Update()
{
    Vector3 movement = oldRot * (transform.position - oldPos);
    oldPos = Player.InverseTransformPoint(transform.position);

    if (movement.z > 0)
    {
        isMovingForward = true;
        isMovingBackwards = false;
    }
    else if (movement.z < 0)
    {
        isMovingBackwards = true;
        isMovingForward = false;
    }
    if (movement.z == 0)
    {
        isMovingBackwards = false;
        isMovingForward = false;
    }

    if (movement.x > 0)
    {
        isMovingRight = true;
        isMovingLeft = false;
    }
    else if (movement.x < 0)
    {
        isMovingLeft = true;
        isMovingRight = false;
    }
    if (movement.x == 0)
    {
        isMovingLeft = false;
        isMovingRight = false;
    }
    oldPos = Player.transform.position;
    oldRot = Player.transform.rotation;
}

}

Sorry for the bump, but can someone please help? These unity forums are starting to become dead. Almost no one helps anymore

That’s easy you have to make an animator component like this

animator anim;

anim = GetComponent<Animator>(); //in the start

anim.Setbool(true, "Name"); //Name of the bool animation to play

that’s it. if it helps please give this message alike and sorry I just saw it now or would have replied back then.