Roll-a-Ball PlayerController script not working

Good Afternoon, I am very new to Unity and to coding as well. I was following the tutorial for Roll-a-Ball and this is the code that I created for the movement script, but when I run this in Unity I get “All compilers errors have to fixed before you can enter playmode”. When I downloaded Unity it is 5.6.0f3 and Visual Studio 2017.

Any suggestions?

[

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {

    public 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, moveVertical);

        GetComponent rb.AddForce(movement);
    }

Sorry there is an error in the code that I had to remove, but even after removing that error I am still failing.

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {

    public 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, moveVertical);

        rb.AddForce(movement);
    }

If the previous poster’s comment helps you fix it, that’s cool. If you have further issues, could you please indicate the line number of the error (as it relates to the posted lines here in the forum). :slight_smile:

1 Like

Try changing this:

GetComponent rb.AddForce(movement);

To this:

rb.AddForce(movement);

Scripts

5471904–559674–PlayerController.cs (2.56 KB)
5471904–559677–CameraController.cs (877 Bytes)
5471904–559680–Rotator.cs (433 Bytes)

1 Like

ty unity_lgpxJiMCscnfGA