- Home /
Question by
synjaqt · Jan 30, 2017 at 07:50 AM ·
javascriptprogrammingvelocity
Can someone help me fix this coding error?
Before I show the code, I would like to explain I did try to fix it and my fix worked kind of, but caused other errors to show up and I just didn't feel like typing all of the errors out on here and I already know it wasn't the right kind of fix I needed. Anyways, here is the code I used
#pragma strict
var rotationSpeed = 100;
var jumpHeight = 8;
private var isFalling = false;
function Update ()
{
//Ball rotation.
var rotation : float = Input.GetAxis ("Horizontal") * rotationSpeed;
rotation *= Time.deltaTime;
var rigidbody: Rigidbody = gameObject.GetComponent(Rigidbody) as Rigidbody;
GetComponent.<Rigidbody> ().AddRelativeTorque (Vector3.back * rotation);
if (Input.GetKeyDown(KeyCode.Space));
{
Rigidbody.velocity.y = jumpHeight;
}
isFalling = true;
}
And the error that showed up is "An instance of type 'UnityEngine.Rigidbody' is required to access non static member 'velocity'"
Comment
Best Answer
Answer by doublemax · Jan 30, 2017 at 07:58 AM
Rigidbody.velocity.y = jumpHeight;
=>
rigidbody.velocity.y = jumpHeight;
Rigidbody is the name of the class, rigidbody in this case is the name of the variable.
Your answer
