Jump Script

Making a simple jump script but for the life of me can’t disallow the player from jumping while in the air. What I tried to do was make an if statement that check if the players velocity in the y direction was zero, if so he could jump; however, the program Unity assigns a velocity of .0003 in the y direction while walking in a straight path, so that doesn’t work.

I am a flash programmer, so Unity is a little bit of a new beast and I don’t quite know the good way to tackle this problem. Any suggestions?

Well, if you aren’t colliding with anything, you must be in the air. So, just create a check OnCollisionEnter and OnCollisionExit that keeps track of the objects you’ve collided with. If you aren’t colliding with any, you can’t jump.

I thought about that; however, if I use that then when you jump and hit a wall you could then jump again in midair. So is there a way to do a direction collision test?

Are you using a Character Controller by any chance? If so, UT has provided a nice scripting solution for you.

I am not using the Ut move function, no… custom move dynamics.

A Character Controller is a component you can add to a Game Object to potentially make controlling a character easier.

Or you can just tag the objects that you’d be landing on top off “Jumpable” and keep track of all objects on collision where transform.tag == “Jumpable.”