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?