Sprite moves by itself (no inputs at all)!

So I have JUST started this 2D Space shooter prototype but the Player sprite moves off down diagonally with out any input, in scene view and when built. It does not do this when I play the build on a different computer so I am thinking it may be that Unity is detecting an input of my ‘S’ and ‘D’ keys on my computer. I have no idea why as the code is the most simple code ever.

Thanks in advance.

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {

    public float speed;

    private Rigidbody2D rb2d;

    // Use this for initialization
    void Start () {
        rb2d = GetComponent<Rigidbody2D>();

    }
   
    void FixedUpdate () {
        float moveHorizontal = Input.GetAxisRaw("Horizontal");
        float moveVertical = Input.GetAxisRaw("Vertical");

        Vector2 movement = new Vector2(moveHorizontal, moveVertical);

        rb2d.AddForce (movement * speed);
    }
}

Well, first, don’t just guess… check whether your theory is correct. Add something like this:

Debug.Log("Inputs Hor:" + Input.GetAxisRaw("Horizontal") + " Ver: " + Input.GetAxisRaw("Vertical"));

Then run it and see exactly what those inputs are.

Then, check your Input settings… chances are pretty good something’s messed up there. Or it could be at the hardware/OS level. Assuming your keyboard keys aren’t actually stuck, maybe Unity thinks you have a joystick plugged in, with the joystick jammed all the way into the corner.

1 Like