Input returns -1 instead of 0

Hello everyone!

I have been working on making the player ship to move, but Input.GetAxis() will default to returning -1 even when I’m not pressing any buttons. I have tried recreating a simpler scene that still has the input just to see if something was broken in the other one, but it is still returning -1.

If anyone could help I would really appreciate it! Thank you!

Cheers, SomeGuy.

Just a guess but you might be missing the input axis you’re interested in, for example:

float translation = Input.GetAxis("Vertical") * speed;
float rotation = Input.GetAxis("Horizontal") * rotationSpeed;

Thanks for helping! I tried implementing you code in to mine, but it still didn’t work since input was still returning -1 and that got multiplied by 10 and still made my ship always zoom to the left.
Here is my code if that helps

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

public class PlayerController : MonoBehaviour
{
    [SerializeField] float speed = 10;
    [SerializeField] float rotationSpeed = 5;

    void Update()
    {
        float translation = Input.GetAxis("Horizontal") * speed;
        float rotation = Input.GetAxis("Vertical") * rotationSpeed;

        Debug.Log(translation);

        float xOffset = translation * Time.deltaTime;
        float newXPos = transform.localPosition.x + xOffset;

        transform. localPosition = new Vector3(newXPos, 
        transform.localPosition.y, 
        transform.localPosition.z);
    }
}

Thank you!

Well, I got it working… in a way. This would only happen once when I first pressed play or modified a script, Input would return -1. If I pressed play a second time, Input would return 0. I’m guessing this is a bug in Unity 2020.3 I’m encountering.

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

Privacy & Terms