Need help with movement

For some reason, my cube starts moving rapidly without any input when I hit play. I know its something wrong with my code but the thing is I copied it directly like in the course and this started happening, I tried a bunch of other codes but it still gives the same result, can someone please help me?

HERE IS THE CODE:

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

public class Mover : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {

    }
    
    //Update is called once per frame
    void Update()
    {
        float xValue = Input.GetAxis("Horizontal");
        float zValue = Input.GetAxis("Vertical");
        transform.Translate(xValue,0,zValue);
    }
}

Perhaps use Input.GetAxisRaw(). Input.GetAxis() smooths the input value and if there is a controller connected it will pick up even the slightest drift. Input.GetAxisRaw() does not have smoothing and may be more tolerant of these drifts

I just tried it and the result is still the same :cry:

There is nothing in this code that will just move the cube. Check if there are any other components attached to the cube. If it’s all ok, then there may be some type of controller attached that’s pushing on some axis

Here is a screenshot of the components:

What I want to add is, it’s like it’s focused on the negative button of the Horizontal input (a) and the positive button for the Vertical input (w) like a joystick is facing the upper right, but when I press “d” or “s”, it moves in the opposite direction until I release, I have no controller or joystick attached to my pc, I even went to my devices and printers to confirm. Thank you for your time, I appreciate it :star2:

2023-06-01 16-22-14 (online-video-cutter.com)

I fixed it, it turns out that maybe something is acting like a joystick, I’m not sure what tho, so I just changed “Get motion from all joysticks” in each Vertical and Horizontal Input to “Joystick 16”. Thank you for your help!

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

Privacy & Terms