Why doesn't my rigidbody.AddForce work?

Here is the code:

using UnityEngine;
using System.Collections;

public class PlaterMovement : MonoBehaviour {

public float moveSpeed;

private Vector3 input;

void Update () {

	//The code for moving up/down and left/right
	input = new Vector3 (Input.GetAxis("Up/Down"),0,Input.GetAxis("Left/Right"));
	rigidbody.AddForce(input);
}

}

And this is my error:

Assets/Scripts/PlaterMovement.cs(19,17): error CS0119: Expression denotes a type', where a variable’, value' or method group’ was expected

Hi! What Unity are you using?

Try when you use rigidbody use

GetComponent<Rigidbody>().addForce

Try this instead:

using UnityEngine; 
using System.Collections;

public class PlaterMovement : MonoBehaviour {

     public float moveSpeed; // this better be something like 500 if you want to see some movement

     private Vector3 input;
     private Rigidbody r;

void Start () {
    r = transform.GetComponent <Rigidbody> ();
}

void Update () {

         //The code for moving up/down and left/right
         input = new Vector3 (Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
         r.AddForce(input * Time.deltaTime * moveSpeed);
     }

Input.GetAxis (“Horizontal”) gets the right and left arrows, and Input.GetAxis (“Vertical”) gets the up and down arrows. I assume this is what you wanted.

Physics needs to be done in FixedUpdate(), not in the Update(), so you should change that. Also you should use Horizontal and Vertical instead of Up/Down and Left/Right (Unless you renamed it to that).

void FixedUpdate () {
   //The code for moving up/down and left/right
   input = new Vector3 (Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
   rigidbody.AddForce(input);
}

Well, I see 3 mistakes in your code:

  1. Use FixedUpdate() for physics and not Update().
  2. Use Input.GetAxis(“Horizontal”) and Input.GetAxis(“Vertical”).
  3. Use GetComponent.() and not just rigidbody.

So, you sould have something like this:

void FixedUpdate () {
	input = new Vector3 (Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
	GetComponent.<Rigidbody>().AddForce(input);
}