I’m a bit of a beginner with Unity and I have this short script to move a ball around with WASD and cause it to jump by hitting the space key, but I can’t get the ball to jump more than once.
#Here is what I have
function Start() {
GetComponent.().drag = 1;
}
var jumpHeight = 8;
private var isFalling = false;
function Update () {
//Sets up keys to move the ball
var ballRotationX : float = Input.GetAxis ("Horizontal") * 2000;
var ballRotationZ : float = Input.GetAxis ("Vertical") * 2000;
ballRotationX *= Time.deltaTime;
ballRotationZ *= Time.deltaTime;
GetComponent.<Rigidbody>().AddTorque(ballRotationX, 0, ballRotationZ);
if (Input.GetButtonDown("Jump") && isFalling == false) {
GetComponent.<Rigidbody>().velocity.y = jumpHeight;
isFalling = true;
}
}
function onCollisionStay ()
{
isFalling = false;
}