How to trigger Animations on Entities

Setting up your controller

In your registerControllers add triggerableAnim to your controller like so

@Override
public void registerControllers(ControllerRegistrar controllers) {
    controllers.add(
        new AnimationController<>(this, "baseAnim", event -> PlayState.CONTINUE)
        .triggerableAnim("death", RawAnimation.begin().thenPlayAndHold("death"));
}

You can add more triggers for each animation you want to call.

Calling the trigger

To call the trigger, you will simply need to call triggerAnim wherever you wish to use the trigger. Here is an example of calling on the die method of an Entity to play a death animation.

@Override
public void die(DamageSource source) {
    this.triggerAnim("baseAnim", "death");
    super.die(source);
}

Last updated