Hello! A huge thank you to Albertos for helping with the movable ground! Now the character’s animation is all wonky… I don’t know how to fix it all up, but it’s quite annoying to say the least. Jumping function works, just the animation is all messed up…
Here is the project: PlayCanvas | HTML5 Game Engine
The Code:
var Player = pc.createScript('player');
Player.attributes.add('jumpPower', { type: 'number', default: 500 });
// initialize code called once per entity
Player.prototype.initialize = function () {
this.state = 'idle';
this.falling = false;
this.entity.collision.on('collisionstart', this.onColllision, this);
};
// update code called every frame
Player.prototype.update = function (dt) {
if (this.app.keyboard.wasPressed(pc.KEY_SPACE) || this.app.keyboard.wasPressed(pc.KEY_UP)) {
this.jump();
}
};
Player.prototype.onColllision = function (ev) {
if (ev.other.tags.has('ground')) {
this.state = 'run';
this.falling = false;
this.entity.anim.setBoolean('jump', false);
}
};
Player.prototype.jump = function () {
const self = this;
if (this.state != 'jump') {
this.state = 'jump';
this.falling = true;
this.entity.anim.setBoolean('jump', true);
this.entity.rigidbody.applyImpulse(0, this.jumpPower, 0);
}
};
Hi @OneLife!
You need to add conditions to your transitions, just like you did for the Jump animation. You can set the correct condition by script. That way, the anim state graph knows exactly which animation should play.
Right now, the Hit animation always overrides the others, because there are no conditions set for its transition.
Ok, so I think I fixed it? Only thing that isn’t really working would be the jump animation. But my character doesn’t die as soon as he hits the ground 
Good job!
I suggest trying an Exit Time of 1 on the transition from the Jump state to the Run state. This will give your Jump animation enough time to play before the Run animation starts.
Ok! I tried that and it didn’t seem like it did anything?
Currently you have applied the same conditions on both transitions (to the Jump state and from the Jump state). As you can see on the image, my suggestion regarding Exit Time was only meant for the transition from the Jump state (to Run state). Also, the boolean you have applied on this transition should be set to false. (Maybe if you set this boolean to false, you don’t need Exit Time at all).
I did a quick test and can confirm that both options work. You can either use Exit Time or rely on the Jump
boolean being set to false for the transition back.
There’s also a problem in your script. The boolean is called Jump
with a capital letter. That means you need to use a capital letter in your code as well.
Replace
this.entity.anim.setBoolean('jump', true);
with
this.entity.anim.setBoolean('Jump', true);