I need help for a jumping script maybe a tutorial

yes i did use dynamic rigidbody

ask him to help me?

because i looked at the thread but i didn’t really understand the code and i dont known how to do that kind.

Can you share your project please, then I can try to assist you.

https://playcanvas.com/editor/project/835736

You can try to add the code below inside the update function of your firstPersonMovement script. You can adjust the force value to get the right result.

    var force = 500;
    if (this.app.keyboard.wasPressed(pc.KEY_SPACE)) {
        this.entity.rigidbody.applyImpulse(0, force, 0);
    }

did i add it right? @Albertos

like i said im new to coding iv’e started learning 1 week ago

You did it right. You just have to save your script to apply the changes.

i saved it but i cant jump or is my force wrong?

I see there is already a force variable defined. So we have to change the name of the variable. The current force can also a little higher I guess.

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

image
@Albertos

Yes, that’s right, but I think you accidentally deleted the line below from the original script, so you need to place it back.

   var force = this.force;

ok it worked but do u know how to make it not infinite jump.

yeah i think i messed it up because its falling slowly and jumping infinintly.

There’s not really a good easy way to do this. The easiest way is to use a timer or to check the current height of your player. But both are not ideal in all situations.

ok

A more advanced option is to use a raycast to see if it can detect ground or not.

i need help fixing the jumping mechanism i keep slowly falling and infinite jumping here is the code i used
Screenshot 2021-10-08 1.05.26 PM

It’s not something that can be fixed. You have to adjust the rigidbody values to get the best result. Please check my own topic about it.