/playanimation

This feature is exclusive to Bedrock Edition and Minecraft Education.
 
/playanimation
Permission level
required

1

Restrictions

Cheat only

Sends an animation request to clients to make one or more entities play an animation. This command has an equivalent function in the script API: Entity.playAnimation.

Usage

This command only sends an animation request to client sides. The server side doesn't process the animation at all.

If the target entity is not loaded on the client, the client cannot receive the animation request.

The client processes the request based on the contents of its resource packs, so players using different resource packs in the same server may see different animations.

Animation controller

Animation controllers are state-machines. State machines are a special kind of logic management, that relies on a series of states. Each state has three properties:

  • What to do in the current state
  • Transitions
  • The fade-out duration when transitioning to another state

Each transition has two properties:

  • The target state to transition into
  • The condition to transition into the target state

A state machine can be in only one state at a time. For example if you play an animation on the animation controller controller.animation.player.root on a player, then any other player animations such as sneaking, walking, hand moving, swimming, sleeping, jumping etc. won't play on that player, until this controller returns to a vanilla state.

In an animation controller, there are two types of states:

  • Animation Specified State
    • Created by /playanimation.
    • Doesn't have a name. The animation is used as the unique identifier of the state.
    • Contains animation for what to do in the current state, blend_out_time for fade-out duration, and transitions. Each transition contains a next_state and a stop_expression.
    • The transitions are in an ordered list. Transitions added into the list earlier are checked earlier in each tick. So, when there are multiple transitions whose conditions are met, only the one that is added into the list earlier is executed.
  • Resource Pack Defined State
    • Defined by resource packs.
    • Has a name. Its name is used as the unique identifier of the state.
    • Contains animations for what to do in the current state, transitions for the transitions, and blend_transition for fade-out duration.
    • The transitions are in an ordered list. Transitions at the front of the list are checked earlier in each tick. So, when there are multiple transitions whose conditions are met, only the topmost one is executed.

/playanimation command cannot interact with Resource Pack Defined States, except to add a transition (into an Animation Specified State) with next_state being one of them.

Animation controllers can be defined for an entity type by resource packs with several Resource Pack Defined States (see also official doc). Animation controllers can also be created by this command as described below. There are also animation controllers in behavior packs running on the server side, but they do not control the animation.

Animation controllers on an entity are not saved and are cleared when the entity becomes unloaded on the client, or when the player leaves and rejoins the game.

Animation controllers on an entity return to their default states when the resource pack is reloaded by minimizing or taping out the client game window, but states in the animation controllers won't be cleared.

Animation controller controller.animation.player.root on a player returns to its default state when the player opens the dressing room, but states in the animation controller won't be cleared.

Behavior

When the client receives the request, it first creates the specified animation controller on this entity if not existing. Then, the client adds a new Animation Specified State of the specified animation into the controller and sets the blend_out_time of this state. Then adds a transition with the next_state and the stop_expression into this state. Finally, it sets the current state of the controller to this new state.

If the specified controller already exists on the targeted entity, and the Animation Specified State of the specified animation already exists in the controller, when the client receives the request, the blend_out_time of this Animation Specified State is updated to the new value. And then, if in this state there's no transition that has the same next_state and the same stop_expression, a new transition with the next_state and the stop_expression is added into this state. Finally, it sets the current state of the controller to this state.

If specifying an animation controller defined by resource packs, the command work the same as described above. But note that because this command cannot interact with Resource Pack Defined States (except to add a transition with next_state being one of them), after playing an animation, to make the controller return to a Resource Pack Defined State, you have to make sure an Animation Specified State has a transition with next_state being a Resource Pack Defined State.

List of animations

Name Description Version added Stackable Needs animation controller Possible usage
animation.humanoid.base_pose Original animation of humanoid (player) No No Reset any animation
animation.ghast.scale Scales body, legs, arms to size of ghast. Yes No
animation.humanoid.riding.legs Animation of sitting.
animation.humanoid.celebrating This animation plays when pillagers celebrate their victory in raid.
animation.humanoid.big_head This just scales your head.
animation.agent.move Levitates your body
animation.armor_stand.athena_pose
animation.armor_stand.brandish_pose
animation.armor_stand.cancan_a_pose
animation.camel.walk This animation will make your body wobbly 1.20
animation.camel.sit_down 1.20
animation.camel.sit 1.20
animation.camel.stand_up 1.20
animation.camel.dash 1.20
animation.sniffer.walk 1.20
animation.sniffer.longsniff 1.20
animation.sniffer.search 1.20
animation.sniffer.dig 1.20
animation.sniffer.stand_up 1.20
animation.sniffer.feeling_happy 1.20
animation.humanoid.tooting_goat_horn Animation makes you point right hand. 1.20 Can be used to point item in your hand, for showing it.
animation.humanoid.holding_brush Makes item that your holding bigger. 1.20 Yes
animation.humanoid.brushing This animation will make item your holding move like brush. 1.20
animation.armadillo.peek Moves your head side to side then dislocates it. 1.21
animation.armadillo.unroll 1.21
animation.breeze.idle Slowly 1 pixel wide moves your head down and up. 1.21
animation.breeze.jump Your body charges then jumps really high. 1.21
animation.breeze.shot 1.21
animation.player.holding_heavy_core Makes item in your hand smaller. 1.21.50 Yes
animation.armor_stand.holding_heavy_core Same as animation.player.holding_heavy_core 1.21.50
animation.creaking.walk You’ll be twitching when moved. 1.21.50
animation.creaking.attack Your body would twitch. 1.21.50
animation.creaking.sway Your arm would twitch. 1.21.50
animation.creaking.twitch You’ll twitch 1.21.50

Tips and Tricks (WIP)

Animation controller
Smooth intro transition for animation

Syntax

playanimation <entity: target> <animation: string> [next_state: string] [blend_out_time: float] [stop_expression: string] [controller: string]

Arguments

entity: target: CommandSelector<Actor>

Specifies the targeted entities.
Must be a player name or a target selector.

animation: string: basic_string

Specifies a state (Animation Specified State) by specifying an animation. The state is added into the controller and set as current state of the controller.
Must be a string. And it must be a single word that has no space or a double-quoted string (When quoted, \ can be used to escape characters).
Should be an animation name (e.g. animation.wolf.angry for any entity type), or an animation shortcut defined under the Json path "minecraft:client_entity"."animations" in the <a_resource_pack>/entity/<entity_name>.entity.json file (e.g. wolf_angry for only wolf entity). Animation controller shortcuts under this Json path do not work here.
Be careful when using animations with .v1.0 at the end because it may be incompatible with the version of current world, this may result in lagging and a possible crash.
If the entered string isn't a valid animation in resource packs, the client does not respond to the animation request at all.

next_state: string: basic_string

Specifies the next_state by specifying an animation (of an Animation Specified State) or a name (of a Resource Pack Defined State). Defaults to "default" if not specified.
Must be a string. And it must be a single word that has no space or a double-quoted string (When quoted, \ can be used to escape characters).
Can be an animation shortcut defined under the Json path "minecraft:client_entity"."animations" in the <a_resource_pack>/entity/<entity_type>.entity.json file (e.g. wolf_angry for only wolf entity). Animation controller shortcuts under this Json path do not work here. Animation names do not work here.
Can also be the name of a Resource Pack Defined State under the Json path "animation_controllers"."<controller_name>"."states" in the <a_resource_pack>/animation_controllers/<entity_type>.animation_controller.json file.
If a Resource Pack Defined State and an animation shortcut have the same name, the next state becomes an Animation Specified State that plays both animations in the Resource Pack Defined State and the animation from shortcut.
If the entered string is a valid animation shortcut, but there's no such an Animation Specified State in the controller, the controller can still transition into this non-existent state and be stuck there. It cannot transition into other states, until this state is created into this controller by another /playanimation command, or the controller is changed into another state by /playanimation command.
If the entered string isn't a valid animation shortcut or a valid Resource Pack Defined State name, the next state becomes an Animation Specified State that plays no animation.

blend_out_time: float: float

Specifies the duration of the fade-out when the state transitions into another state. Defaults to 0 if not specified.
Must be a [Float]Single-precision floating-point number (from -(2-2-23)×2127 (≈-3.4×1038) to (2-2-23)2×127 (≈3.4×1038) ).

stop_expression: string: basic_string

Specifies the conditions for transitioning into the next state.
Must be a string. And it must be a single word that has no space or a double-quoted string (When quoted, \ can be used to escape characters).
Should be a Molang expression. Defaults to query.any_animation_finished if not specified.
For example, if you want the animation to end when the player starts sneaking: "query.is_sneaking" or "return query.is_sneaking;".
For another example, after running the following two commands, when the player jumps, it quickly switches between the two animations:
  • /playanimation @a riding.legs riding.arms 0 query.is_jumping controller_name
  • /playanimation @a riding.arms riding.legs 0 query.is_jumping controller_name
Since this Molang expression is executed every tick when the controller is in this state (the Animation Specified State specified by the animation: string), this can also be used to set entity Molang variables. An example of this is that using "variable.test_variable = 1234; return 0;" sets the Molang variable variable.test_variable to 1234. It is possible to set multiple Molang variables at once with this, an example of that is "variable.test_variable_a = 1234; variable.test_variable_b = -9876; return 0;". This can be useful for animations that require certain entity Molang variables to be set in order to work and function properly.
Note: When setting the entity Molang variables, return 0; is used to make the controller stuck in the state, which can be omitted because complex Molang expressions return 0 by default when there's no return expression, e.g. "variable.variable_name = value;". But the semicolon right after the value is required, or else it just produces a content log error. Another important thing to note is that this is client-side only, meaning that the variables are only set for clients who has the entity loaded when the command was run, and the variables reset when the entity is unloaded from the client. Also, it is important to pay attention to the checking order between multiple transitions as described above. Also note that a transition that has the same next_state and the same stop_expression with an existing transition cannot be added into the transitions list as described above, but adding some spaces into stop_expression can avoid this. Also, the animation specified in the animation: string must be a valid animation in order for setting the Molang variables to work.

controller: string: basic_string

Specifies a controller on the target entity. Defaults to "__runtime_controller" if not specified.
Must be a string. And it must be a single word that has no space or a double-quoted string (When quoted, \ can be used to escape characters).
Can be any string, or an animation controller from a resource pack defined under the Json object "animation_controllers" in the <a_resource_pack>/animation_controllers/<entity_type>.animation_controller.json file.

Result

CommandTriggerBedrock Edition
Anythe arguments are not specified correctly Unparseable
if entity: target fails to resolve to one or more online entities (named players must be online) Failed
OtherwiseSuccessful

Output

CommandEditionSituationSuccess Count
AnyBedrock EditionOn fail0
On success1

Example

To make piglin brutes perform a "victory dance":

/playanimation @e[type=piglin_brute] animation.piglin.celebrate_hunt_special a 0

To make the foxes sit down until they leave the ground. Once leaving the ground, the foxes become in sleep state:

/playanimation @e[type=fox] sit sleep 0 "!query.is_on_ground" controller_name
Or:
/playanimation @e[type=fox] sit sleep 0 "query.is_on_ground == 0.0" controller_name

To make a very large entity (change the last value to something else and rerun to make it even bigger):

/playanimation @s animation.ghast.scale a 0 false la

To make a player sit down until they move:

/playanimation @a animation.player.riding.legs a 0 query.is_moving controller_name

To make a player's legs flip upside down into their body until they jump:

/playanimation @a animation.player.move.legs.inverted a 0 query.is_jumping controller_name

To make a player's body freeze and stop all player animations from playing on that player (Note: the animation controller has to be controller.animation.player.root for this to work):

/playanimation @s sleeping a 0 true controller.animation.player.root

To make the player upside down (run the previous command first):

  1. /playanimation @s animation.player.base_pose.upside_down a 0 false a
  2. /playanimation @s animation.player.move.legs.inverted a 0 false b
  3. /playanimation @s animation.player.holding a 0 false c
  4. /playanimation @s animation.player.bob a 0 false d
  5. /playanimation @s animation.player.look_at_target.inverted a 0 false e
  6. /playanimation @s animation.player.move.arms a 0 false f
  7. /playanimation @s animation.player.attack.positions a 0 false g
  8. /playanimation @s animation.player.attack.rotations a 0 false h

History

Bedrock Edition
1.16.100beta 1.16.100.52Added /playanimation.

Navigation