How To Write Script That Allows Player To Jump only for one time

here is the link of the code:PlayCanvas | HTML5 Game Engine

@MATURE There are several ways to prevent the double or multiple jumps while in there air. This is a question commonly asked in this forum. I see that you already have the first part included and you are able to jump. One method is to give the plane a tag name of “ground”. Since your player is not falling through the plane that means that you have collision and rigid body configured for the ground. Your player should also have these enabled. In the movement script you will have to create a collision event that triggers when the player is on the ground. At this point you can use a flag to figure out in code if the player is on the ground then jump. However, if the player is not on the ground do not execute this part of your script.

    if(this.app.keyboard.wasPressed(pc.KEY_SPACE) === true){
        this.entity.rigidbody.applyImpulse(0, 1000, 0);
    }  

I hope this helps. Further you can do a search of this forum. This question has been asked numerous times so maybe this will also be helpful.

https://forum.playcanvas.com/search?q=double%20jump

2 Likes

can you write the code i don’t know anything about coding in js

You should start with some JS tutorials to get more familiar with the language. There are plenty available online.

Afterwards study the Scripting section on the User Manual to get started with coding in PlayCanvas:

https://developer.playcanvas.com/en/user-manual/scripting/

3 Likes