Only jump when character is on the ground

Hello,

I tried to add jumping in the first person controller with applyImpulse and it worked but it can also jump when its not on the ground so if you press space very fast you can go as high as you want. Is there some sort of line with wait or that you can only jump when your character is on the ground?

My project:
https://playcanvas.com/editor/scene/646173

The script i use is FirstPersonMovement

Thanks!

I am not sure if this would work, but you could try doing an if statement to check if the character has reached a certain height. If it has not, then let it jump, otherwise you can keep it on the ground.

Something like -


if (this.entity.getPosition().y < //maximum height) 
     {//jump}


I tried it and it worked! thanks a lot!!

You’re welcome. @EsterZ, can you make a basic space shooter game for my project? It’s pretty urgent and I need to find a team member, since I need to work on something else. I will give all due credit to you. Please let me know if you are interested.

No sorry i dont really have time for that im working in playcanvas for school and it needs to be finished within 2 weeks and there is al lot to do.

That’s OK, just wanted to know

Using pos.y for “can jump detection” prevents you from making any kind of nice vertical maps. The height difference in maps is often what makes them attractive, in e.g. FPS shooters. Climbing up the ladders, jump over gaps, walking downhill etc.

I am using this script:

Ground detection is based on Ammo.js Capsule collision and you can only jump once every 500ms

It’s not perfect yet, but I think we need to collaborate more on “this kind of stuff should just work” essentials.

If you have any ideas or actual code to improve the script, just write here please

You can probably look at @EsterZ 's code in the project. I suggested something earlier on in the thread and it seems to have worked for @EsterZ.