if (this.app.keyboard.wasReleased(pc.KEY_SPACE) && this.app.keyboard.isPressed(pc.KEY_W)) {
if (this.jumpTimer <= 0) {
this.jumpTimer = 0.5;
setTimeout(function(){
this.entity.rigidbody.applyImpulse(0, 700, 0);
this.entity.children[0].animation.play('Jumping');
setTimeout(function(){ // < ----- you can also do set interval which runs that code in that time period that you picked.
if (app.keyboard.isPressed(pc.KEY_W))
app.root.findByName('Player TPC').children[0].animation.play('Walking', 0.2);
},800);
}.bind(this), 100);
}
} else if (this.app.keyboard.wasReleased(pc.KEY_SPACE) && this.app.keyboard.wasReleased(pc.KEY_W)) {
this.entity.children[0].animation.play('Idle', 0.2);
}
else if (this.app.keyboard.isPressed(pc.KEY_SPACE) && this.app.keyboard.wasReleased(pc.KEY_W)) {
this.entity.children[0].animation.play('Idle', 0.2);
}
else if (this.jumpTimer >= 0) {
this.jumpTimer -= dt;
}
else {
this.jumpTimer = 0;
// this.entity.anim.setBoolean('justJumped', true);
}
I’m using this to detect and predict when player is moving and jumping and to controll animations, part with setTimeout, (blend - animation duration) so it looks natural (as all animations are looped) those else ifs preditcs if other combinations are not pressed and limits it since players do only jump when moving forward (W pressed space released)
I’m also using PlayerAnimationHandler
PlayerAnimationHandler.prototype.checkButtons = function () {
var app = this.app;
var w = app.keyboard.isPressed(pc.KEY_W) || app.keyboard.isPressed(pc.KEY_UP);
var a = app.keyboard.isPressed(pc.KEY_A) || app.keyboard.isPressed(pc.KEY_LEFT);
var s = app.keyboard.isPressed(pc.KEY_S) || app.keyboard.isPressed(pc.KEY_DOWN);
var d = app.keyboard.isPressed(pc.KEY_D) || app.keyboard.isPressed(pc.KEY_RIGHT);
if (w && !s) {
if (a && !d) {
this.direction = 'Walking'; // Run Forward Left
} else if (d && !a) {
this.direction = 'Walking'; //Run Forward Right
} else {
this.direction = 'Walking'; // Run Forward
}
} else if (s && !w) {
if (a && !d) {
this.direction = 'WalkBack'; // Run Backward Left
} else if (d && !a) {
this.direction = 'WalkBack'; // Run Backward Right
} else {
this.direction = 'WalkBack'; // Run Backward
}
} else if (a && !d) {
this.direction = 'WalkLeft'; // Run Left
} else if (d && !a) {
this.direction = 'WalkRight'; // Run Right
} else {
this.direction = 'Idle'; // Idle
}
};
I’ve tried this method [SOLVED] Third Person Jump and Play Animation - #4 by Albertos
but it lacks some key features as preventing multiple jumps + animation only plays on isPressed not the full anim, and wasReleased totally breaks the anims
Any ideas? heard setTimeout is not good to use