I made movement physics and when i play the object goes to 1 direction WITHOUT ME PRESSING ANYTHING!

HELP i made myself my first movement script and when i press play my cube just goes 1 direction without me pressing anything please help ASAP

7036132--834001--script.PNG

If you post your script in code tags, people are far more likely to look at it (99% of the time I do not bother looking at problems with images of scripts because I am too lazy to type it out to test it), here it is for you:

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

public class MoveCube : MonoBehaviour
{
    public float speed = 0.1f;

    void Update()
    {
        float xDirection = Input.GetAxis("Horizontal");
        float yDirection = Input.GetAxis("Vertical");
        Vector3 moveDirection = new Vector3(xDirection, 0, yDirection);
        transform.position += moveDirection * speed;
    }
}

Whilst we are on that subject, it’s better not to use caps lock.

The code seems to work OK for me. Here are some potential problems you may be having:

  1. You don’t say which direction… do you have a rigidbody on the cube that is under gravity?
  2. Do you have a controller connected to your PC that is producing constant output?
  3. Try adding Debug.Log("moveDirection: " + moveDirection); to your Update() method and check your console log to see what the inputs are.
  4. Is the cube starting off in collision with another object? I.e. is it next to another cube with a rigidbody on it?