Problems with jumping script

So i created this jumping script so the player cannot jump if he doesn’t touch the ground. But sometimes even when i roll on solid ground, the ball doesn’t jump at all. This really annoys me, and yes i have just started using Unity so i don’t understand much about scripting with JavaScript. here’s the script i’m using. I really hope someone would help me out so i could finally share my game with my friends :slight_smile:

#pragma strict
//rotationspeed Unityssä
var rotationSpeed = 100;
//variable jumpheight
var jumpHeight = 8;
//käytännössä jos putoaa, ei voi tehdä jotakin
private var isFalling = false;

function Update ()
{

//Miten rotation toimii
var rotation : float = Input.GetAxis (“Horizontal”) * rotationSpeed;
rotation *= Time.deltaTime;
//miten kohde liikkuu, vector back, vector left, vector right, yms. Vector.back * -1 kääntää suunnat vastakkaisiksi
rigidbody.AddRelativeTorque (Vector3.back * rotation);

if (Input.GetKeyDown (KeyCode.W) isFalling == false)
{
// Y AXIX on UP AND DOWN
rigidbody.velocity.y = jumpHeight;
}
isFalling = true;

}

function OnCollisionStay ()
{
isFalling = false;
}

Perhaps OnCollisionStay() is not reliable enough for what you want to do, for example you may want to jump while there’s an indistinguishable 1 pixel space between the ball and the floor.

You could try something like this:

function OnCollisionExit ()
{
isFalling = true;
}

function OnCollisionEnter ()
{
isFalling = false;
}

and remove “isFalling = true” from your Update()