So I am trying to implement a jump mechanic in my code.I’m trying to create a first person game but to be honest I suck at coding. I managed to find and figure out how the first person controls work but I have a problem with implementing the jump mechanic
I did the following:
if (app.keyboard.isPressed(pc.KEY_SPACE)){
this.entity.rigidbody.applyImpulse(0,2,0);
}
but if I keep mashing space I just fly off. IDK how to make sure I can only jump while in contact with another surface or at least how to time out the jump button
NOTE: my floor is constanly moving upwards so I presume an “on colission” trigger would be my best choice
EDIT:
I added a non collision trigger but it’s still not working
˙˙˙
this.entity.collision.on(‘jumpstart’, this.onJumpStart, this);
onJumpStart = function (result) {
if (result.other.rigidbody) {
if(result.other.name === "Fallblock"){
if (app.keyboard.isPressed(pc.KEY_SPACE)){
this.entity.rigidbody.applyImpulse(0,2,0);
}
}
}
};
˙˙˙
FINAL EDIT:
I figured it out thanks to this guys project
https://playcanvas.com/project/569492/overview/tutorial-third-person-camera