- Home /
Following the Unity 'Roll-a-Ball' tutorial but ball won't move
I have followed all of the steps up to the point where the ball is about to be moved, my code is
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, moveHorizontal);
rigidbody.AddForce(movement);
}
}
and I have the playerController.cs linked with the Player object. When I click play and try to move the object nothing happens and I get the error:
Unity MissingComponentException: There is no 'Rigidbody' attatched to the "Player" game object, but a script is trying to access it.
The tutorial didn't mention having to add this - what am I meant to do?
Comment
Answer by jcv8000 · Apr 02, 2015 at 08:50 PM
You need the Rigidbody component on the player object for the script to use 'rigidbody.AddForce(movement)'. If there's no Rigidbody component attached to the player, rigidbody.AddForce has no rigidbody to use.
Click on the gameobject in the editor, and in the Inspector there should be a button that says "Add Component", then click the Physics section and select Rigidbody.
Your answer
![](https://koobas.hobune.stream/wayback/20220613192008im_/https://answers.unity.com/themes/thub/images/avi.jpg)