Hi,I’m a new beginner, since i was trying to use the function rigidbody.AddForce for the first example project on the official website. I just can not figure out why this happened. PS: I had already add the Rigidbody component to the ball as the tutorial presented.
You are not accessing it through object…you are accessing it directly through class…
Replace “Rigidbody” with “rigidbody”
EDIT:
private Rigidbody myRigidbody;
void Start(){
this.myRigidbody = this.GetComponent<Rigidbody>();
}
Now use myRigidbody instead of Rigidbody
GetComponent().AddForce(movement);
You might also want to cache it, instead of grabbing it every FixedUpdate:
public class PlayerController : MonoBehaviour {
private Rigidbody rb;
void Awake(){
rb = GetComponent<Rigidbody>();
}
void FixedUpdate(){
//Your code
rb.AddForce(movement);
}
}