Need help i cannot understand this jumping on sprite i dunno whats wrong on my code
heres my project
https://playcanvas.com/editor/scene/1620286
var Jump = pc.createScript('jump');
var force = 14; //You can change the value if you want.
// initialize code called once per entity
Jump.prototype.initialize = function() {
this.app.keyboard.on(pc.EVENT_KEYDOWN, this.onKeyDown, this);
};
// update code called every frame
Jump.prototype.update = function(dt) {
if (this.app.keyboard.isPressed(pc.KEY_SPACE)) {
this.entity.sprite.play("jump");
if (this.jumpTimer <= 0) {
this.jumpTimer = 0.5;
setTimeout(function(){
this.entity.rigidbody.applyImpulse(0, force, 0);
}.bind(this), 100);
}
}
else if (this.jumpTimer >= 0) {
this.jumpTimer -= dt;
}
else {
this.jumpTimer = 0;
}
};