Super Noob Question (572203)

I am doing the tutorial for the Roll-A-Ball game. I am on the “Move the Player” step, and the code that the tutorial has you typing out doesn’t seem to work.

Here is a copy of the code that I have typed out myself:

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour
{
    void FixedUpdate ()
    {
        float moveHorizontal = Input.GetAxis ("Horizontal");
        float moveVertical = Input.GetAxis ("Vertical");

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

        Rigidbody.AddForce(movement);

    }
}

And here is a copy of the error that it is throwing: Assets/Scripts/PlayerController.cs(13,27): error CS0120: An object reference is required to access non-static member `UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3, UnityEngine.ForceMode)’

It’s having an issue with the Rigidbody.AddForce, and I can’t seem to get it to resolve. I have done some research, but as I am a new to doing any of this, it’s all a bit above my head at the moment. L’il help?

Thanks much.

You are probaply using unity 5

in Unity 4 a GameObject could access its rigidbody component directly with rigidbody.AddForce()

in Unity 5 rigidbodys are access in the same way like every other Component with the GetComponent().AddForce(…)
GetComponent().DoThis();

the programming structure accessing components is now consistent

line 13 is wrong.

replace
Rigidbody.AddForce(movement);

with

this.GetComponent<Rigidbody>().AddForce(movement);
2 Likes

Thanks bro. No idea what I am doing. Baby steps, right? :slight_smile:

Thanks “tobad”, as of March 18, 2015 your code works in the roller ball project. Your a life saver considering I just started out.