Player Jumping out of scene

Can someone help me with the script?
Player should be able to jump with space bar, it was working but now our player is jumping and not returning.
https://playcanvas.com/editor/scene/2200439

here is script:

https://playcanvas.com/editor/code/1320412?tabs=220371162

Hi @Ashley_Solano!

I see Linear Damping of the rigidbody component is set to zero, so maybe the jump power is just too much? :thinking:

Or maybe Linear Damping should not be set to zero.

1 Like

Made a fork to confirm, its not that. The issue is actually using the setTimeout() function causing odd behavior.
The issue can be solved by removing the setTimeout function and replacing it with:

this.entity.rigidbody.applyImpulse(0, this.jumpPower, 0);
1 Like

Ah I see, probably because this.jumpPower is undefined in the time out. In this case self.jumpPower should be used instead.

1 Like

thank you! This worked, but now our player can only jump once instead of anytime space is pressed.
Any suggestions?
Thanks for the help!

As far I can see on my mobile, the entity that has the ‘ground’ tag is currently part of the player entity. I don’t know your logic, but this doesn’t look correct to me.