jump script error

Hi,I’m new to scripting and Unity and everything. I’m watching a step by step tutorial on making a ball rolling game on Youtube. Even though i wrote the script exactly as the Youtuber did, every time i press w(which i scripted to make the ball jump) my ball does nothing,it can only roll to the left and right. Can someone please tell me what I’m doing wrong? I’m using javascript if that helps.

#pragma strict

var rotationSpeed = 100;
var jumpHeight = 8;

private var isFalling = false;

function Update ()
{
var rotation : float = Input.GetAxis (“Horizontal”) * rotationSpeed;
rotation *= Time.deltaTime;
rigidbody.AddRelativeTorque (Vector3.back * rotation);

if (Input.GetKeyDown(KeyCode.W) && isFalling == false)
{
rigidbody.velocity.y = jumpHeight;
}
isFalling = true;
}

function OnCollsionStay ()
{
isFalling = false;
}

Check this line and see if it might need to go in the bracketed section above it:
isFalling = true;

Also, read the section about using code tags in the stickies.

Thanks for the help but when i put isFalling = true; inside the brackets above,I can only jump once and once only.I want to be able to jump multiple times.Also,where can i find the “code tag by the stickies.”?

just tried it, you misspelt the collision function name.

yeah ive had that before when unity just ignores it if its not spelt correctly :frowning:

Was this originally.

function OnCollsionStay ()
{
isFalling = false;
}

should read

function OnCollisionStay ()
{
isFalling = false;
}

and like fire7side said, put the isFalling inside the function block.

if (Input.GetKeyDown(KeyCode.W) && isFalling == false)
{
rigidbody.velocity.y = jumpHeight;
isFalling = true;
}

should work just dandy now :slight_smile:

Nice find OboShape. Unity ignores it because it’s legitimate. It’s just another function with a different name. Really hard to find. I looked for spelling errors and didn’t see it.

1 Like

Thank you so much for the help.my game works now but i have isFalling = true; outside yet it still works but thanks anyways! :slight_smile:

When posting code, please use code tags.

Yea even after trying to test in a scene. It still took ages scratching my head :slight_smile: lol