Roll-A-Ball tutorial problem, ball wont move

While doing the in-built Roll-a-Ball tutorial I noticed that I cant move the ball despite having the exact same code as well as following the instructions. I’m fairly new to unity and coding in general

public class PlayerController : MonoBehaviour {

    public float speed;

    private Rigidbody rb;

    void Start ()
    {
        rb = GetComponent<Rigidbody>();
    }

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

        Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

        rb.AddForce (movement * speed);
    }

Any help would be appreciated.

Check please this things:

  • Have your ball a rigidbody?
  • Is there a proper keys set in input manager to horizontal and vertical axis?
  • Isn’t your speed too low?

Try to debug your code - it’s should be a first step when You try to solve code problems. You can read more here: Unity - Scripting API: Debug

And a little example for your code:

void Start ()
     {
         rb = GetComponent<Rigidbody>();
         if(rb == null)
         {
             Debug.Log("There is no rigidbody in " + transform.name)
         }
     }

I had this exact problem. Nothing worked until I restarted my computer (I had just installed unity/visual studio) then it completely resolved.

This is all you need to get the ball moving.

    public float speed;

    private Rigidbody rb;

    void Start() {
        rb = GetComponent<Rigidbody>();
    }

    void FixedUpdate() {

        rb.AddForce(1, 0, 0, ForceMode.Acceleration);
    }

Reference: Unity Documentation - Rigidbody.AddForce.