- Home /
Jumping script OnCollisionStay didn't work
Hey im trying to make a jumping script and i need to make it that i can jump only when i am on the ground i have this (sorry for my english im from poland)
#pragma strict
var height = 10;
var isFalling = false;
function Update () {
if (Input.GetKeyDown(KeyCode.Space) && isFalling == false)
{
rigidbody2D.velocity.y = height;
isFalling = true;
}
}
function OnCollisionStay ()
{
isFalling = false;
}
when im press space i jump and isFalling variable is true but when i fell and touch the ground again isFalling is still true help
here a link for a short video that's help you guys better understand this situation: Click here
Answer by robertbu · Aug 08, 2014 at 01:48 PM
You have a 2D app (based on your 'rigidbody2D', but OnCollisionStay() is 3D. You want OnCollisionStay2D().
function OnCollisionStay2D ()
And you could use OnCollisionEnter2D(). Note if you start putting other objects in the scene, you'll have to change/expand this code.
Your answer
Follow this Question
Related Questions
Ground Checker 2 Answers
OnCollision Jump Occurring Twice 1 Answer
3D Game-Making a character jump 3 Answers
Jumping Problem? 3 Answers
How to make the CC(character controller) jump and push 1 Answer