Pressed buttons only plays one frame of the animated script

if (this.app.keyboard.isPressed(pc.KEY_SHIFT) && this.app.keyboard.isPressed(pc.KEY_D)) {
    this.entity.sprite.play(“run”);
    this.entity.rigidbody.applyForce(movementSpeed * 2, 0, 0);
    this.entity.sprite.flipX = false;
}

I’m experiencing an issue where pressing the ‘Shift’ and ‘D’ hotkeys only triggers a single frame of the animated sprite. Ideally, I’d like this key combination to initiate the full run animation.

Hi @350oven and welcome!

Do you stop the sprite animation somewhere else in code or is it overruled by another animation?

You probably need a timer or something to play the animation longer before the next animation is started, but I expect some problems with this.

Another option is to play the animations based on the velocity of the rigidbody instead of the input of the player, but this can be hard to achieve.