Roll A Ball Not Working

Hello everyone, currently trying to work on Roll A Ball as my first major project on Unity. I typed out the code as it says in the tutorial and it didn’t work, so I tried again, and it still didn’t work. So after a few more tries I just copied the finished code at the bottom. It still doesn’t work when I try to move. Regardless of the speed that is set. Here is the code

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour
{
    // Rigidbody of the player.
    private Rigidbody rb;

    // Movement along X and Y axes.
    private float movementX;
    private float movementY;

    // Speed at which the player moves.
    public float speed = 0;

    // Start is called before the first frame update.
    void Start()
    {
        // Get and store the Rigidbody component attached to the player.
        rb = GetComponent<Rigidbody>();
    }

    // This function is called when a move input is detected.
    void OnMove(InputValue movementValue)
    {
        // Convert the input value into a Vector2 for movement.
        Vector2 movementVector = movementValue.Get<Vector2>();

        // Store the X and Y components of the movement.
        movementX = movementVector.x;
        movementY = movementVector.y;
    }

    // FixedUpdate is called once per fixed frame-rate frame.
    private void FixedUpdate()
    {
        // Create a 3D movement vector using the X and Y inputs.
        Vector3 movement = new Vector3(movementX, 0.0f, movementY);

        // Apply force to the Rigidbody to move the player.
        rb.AddForce(movement * speed);
    }
} 

Again I tried myself to type it and it didn’t work, hence why I copied the code at the bottom of the tutorial. So why does it still not work?

I’m assuming obviously I’ve messed up somewhere as I am a total beginner to unity developing. So please let me know what kind of issues would cause this

What version of Unity are you using, and what version of the tutorial are you looking at?

The section of setting up the PlayerInput component is slightly different between Unity 6 and older versions.

I think I figured the issue out, looks like my unity version is 3.17f1, not version 6. And I was looking at unity version 6’s tutorial. I forgot I had downloaded unity to learn it a while ago and clearly forgot to update.

1 Like

You can select different versions of the tutorial to match your version:

But wouldn’t hurt to be on Unity 6 still.