The transition didn't work in Animstategraph

I make a Animstategraph, and add a contidion ‘attack == false’ , when i press down the key and up , the Attack ani play to the end and transition to idle.
Animstategraph

but if i up the key untill the Attack ani is end , it will stop on the last frame on Attack and the keyboard will no longer act.

Hi @fftidus,

Can you try removing the Exit Time value? Don’t put anything there so the animation can exit with this transition at any time.

image

Yes it works , but I hope I can full play the Attack animation, how to make it without exitTime?

For that yes, you will need to set the exit time = 1 for the transition. Not sure what’s not working there, but here is a working example for a jump animation that fully plays on key up:

https://playcanvas.com/editor/scene/1401668

your demo has the same problem!Press down space key , and release it when the ‘Jump’ is end.

So, you are looking to hold the key as long as you like, then try with this code. I’ve updated the project too:

var PlayerMovement = pc.createScript('playerMovement');

PlayerMovement.prototype.update = function (dt) {

    const activeState = this.entity.anim.baseLayer.activeState;
    const isJumping = activeState === 'Jump';

    if (isJumping) {
        this.entity.anim.setBoolean('isJumping', false);
    } else {
        if (pc.app.keyboard.wasPressed(pc.KEY_SPACE) === true) {
            this.entity.anim.setBoolean('isJumping', true);
        }
    }
};
1 Like

And in case you gameplay requires it, you can change the wasPressed method to isPressed to have your character jump continuously while the key is down.

Hope that helps.

:kissing_heart: yes that’s what i want !

1 Like