Question by
noprx805 · Jun 23, 2017 at 04:17 AM ·
scripting problemerror messagescriptingbasics
How do i fix this problem
i was working on a basic 3d platformer as a tutorial but i'm getting the error in mono:
Assets/Ball Control.js(11,19): BCE0020: An instance of type 'UnityEngine.Rigidbody' is required to access non static member 'AddRelativeTorque'.
the code i was using is:
pragma strict
var rotationSpeed = 100;
function Update () { var rotation : float = Input.GetAxis ("Horizontal") rotationSpeed; rotation = Time.deltaTime; Rigidbody.AddRelativeTorque (Vector3.back * rotation);
}
Can anyone help me
Comment
Answer by ChristosKapenis · Jul 03, 2017 at 07:40 PM
Create a new Rigidbody variable called "rb". Then on the Start() function set "rb" to GetComponent<Rigidbody>();
Example:
var rb : Rigidbody;
function Start() {
rb = GetComponent<Rigidbody>();
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612124605im_/https://answers.unity.com/themes/thub/images/avi.jpg)