Debug.log problem

Some reason when i press Up, in debug it says “up” and adds a “left”
and when i press down it does the same thing. Where am i going wrong, i tried everything.

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

public class Drive : MonoBehaviour
{

    public Rigidbody2D rb;

    public Animator anim;

    public float moveSpeed = 60;

    public float x, y;
    public bool moving = false;

    public bool up;
    public bool down;


    private Vector3 moveDir;

    private void Start()
    {
        rb = GetComponent<Rigidbody2D>();
    }

    private void LateUpdate()
    {
        x = Input.GetAxisRaw("Horizontal");
        y = Input.GetAxisRaw("Vertical");

        moveDir = new Vector3(x, y).normalized;

        if (x != 0 || y != 0)
        {
            anim.SetFloat("X", x);
            anim.SetFloat("Y", y);


            if (x > .5)
            {
                moving = true;
                anim.SetBool("isMoving", moving);

                Debug.Log("Right");
            }

            if (x < .5)
            {
                moving = true;
                anim.SetBool("isMoving", moving);

                Debug.Log("Left");
            }

            if (y > .5 )
            {
                moving = true;
                anim.SetBool("isMoving", moving);

                Debug.Log("Up");
            }

            if (y < .5 )
            {
                moving = true;
                anim.SetBool("isMoving", moving);

                Debug.Log("Down");
            }


        }
        else
        {
            moving = false;
            StopMoving();
        }

    }

    private void FixedUpdate()
    {
        if (moving == true)
        {
            rb.velocity = moveDir * moveSpeed * Time.deltaTime;
        }
    }

    private void StopMoving()
    {
        rb.velocity = Vector3.zero;
        rb.Sleep();
    }
}

Do you perhaps intend to be comparing against -0.5f like so:

if (y < -0.5f)

Inputs are generally -1 to 1

PS - same goes for the if (x < -0.5f) comparison I would think…

2 Likes

Thank you so much. I forgot to add the -minus as i forgot the Axis uses + and -.