Walk animation only playing in one direction

my character’s walk animation only plays when the A and W keys are press together. he can move in other directions but the animation won’t play. Can anyone please help, i’m losing my mind here.

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

public class PlayerControl : MonoBehaviour
{
public float moveSpeed = 2.2f;
public GameObject CubeAsimov;
public Animator animator;

void Update()
{
if (Input.GetKey(KeyCode.A))
{
animator.SetBool(“Walk”, true);
transform.Translate(Vector3.left * Time.deltaTime * moveSpeed);
CubeAsimov.transform.localRotation = Quaternion.Euler(0,270,0);
}

if (Input.GetKey(KeyCode.D))
{
animator.SetBool(“Walk”, true);
transform.Translate(Vector3.left * Time.deltaTime * moveSpeed * -1);
CubeAsimov.transform.localRotation = Quaternion.Euler(0,90,0);
}

if (Input.GetKey(KeyCode.W))
{
animator.SetBool(“Walk”, true);
transform.Translate(Vector3.forward * Time.deltaTime * moveSpeed);
CubeAsimov.transform.localRotation = Quaternion.Euler(0,0,0);
}

if (Input.GetKey(KeyCode.S))
{
animator.SetBool(“Walk”, true);
transform.Translate(Vector3.forward * Time.deltaTime * moveSpeed * -1);
CubeAsimov.transform.localRotation = Quaternion.Euler(0,180,0);
}

if (Input.GetKey(KeyCode.W) && Input.GetKey(KeyCode.D))
{
animator.SetBool(“Walk”, true);
CubeAsimov.transform.localRotation = Quaternion.Euler(0,45,0);
}

if (Input.GetKey(KeyCode.D) && Input.GetKey(KeyCode.S))
{
animator.SetBool(“Walk”, true);
CubeAsimov.transform.localRotation = Quaternion.Euler(0,135,0);
}

if (Input.GetKey(KeyCode.S) && Input.GetKey(KeyCode.A))
{
animator.SetBool(“Walk”, true);
CubeAsimov.transform.localRotation = Quaternion.Euler(0,225,0);
}

if (Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.W))
{
animator.SetBool(“Walk”, true);
CubeAsimov.transform.localRotation = Quaternion.Euler(0,315,0);
}
else
{
animator.SetBool(“Walk”, false);
}

if (Input.GetKey(KeyCode.G))
{
animator.SetTrigger(“Attacking”);
}
}
}

The computer is doing exactly what you tell it to here :slight_smile:

        if (Input.GetKey(KeyCode.A) && Input.GetKey(KeyCode.W))
        {
            animator.SetBool("Walk", true);
            CubeAsimov.transform.localRotation = Quaternion.Euler(0,315,0);
        }
        else
        {
            animator.SetBool("Walk", false);
        }

Next time when you post code examples, please use code tags like above.
Also, there is probably a much cleaner way to achieve what you want. I’m not entirely sure what the purpose of that cube is, but you can handle all of your movement in a couple lines of code using something like:

Vector3 moveInput = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
moveInput.Normalize();
transform.position += moveInput * moveSpeed * Time.deltaTime;