ANIMATIONS DOCUMENTATION
Version: 1.21.40.3

Index

Animation Controllers
State Blending
State Transitions
States
Channels (Rotation, Position, Scale)
Entity Animation Format Examples
Getting Started
Adding Animations
Animation Hierarchy
Upgrade from v1.10 to v1.17.30
Upgrade from v1.17.30 to v1.18.10
Upgrade from v1.18.10 to v1.18.20
Upgrade from v1.7 Beta to v1.8
Upgrade from v1.8 Beta to v1.10
Key Frames
Interpolation
Names
Overview
Render Controllers
Examples
Getting Started
Transforms
Back to top

Animation Controllers

Animation controllers decide which animations to play when. Each controller contains a list of states that play one or more animations, each of which can be blended by a Molang expression if so desired. Controller files are stored as JSON in the animation_controllers folder

Animation Controller Format:

Back to top

State Blending

If you would like there to be a cross-fade between states when transitioning, simply set "blend_transition" to the time you would like the system to take in blending between the two states. This is done as a simple lerp between the two states over the time specified.

For example:

Back to top

State Transitions

A state can specify any number of transition scripts, listed in order. Each transition has a target state to switch to, and a script for whether it should switch or not. For each transition in order, evaluate the script, and if it returns non-zero, switch to the specified state immediately. NOTE: Only one transition will be processed per frame.



For example:

Back to top

States

A state defines a group of animations to process (each of which can have it's own blend value). Each state has an optional variables section, listing any number of variables that referenced animations can use. Each state also has one or more animations, using the name given in the entity's definition json.

State Variables

Variables are either set by the game or by a user defined script that can be found in the entity definition json found in definitions/entity/.json. Variables have their value set by a Molang Expression. They can also have their value remapped via a linearly-interpolated curve.

For Example:

This defines a controller with a single state. It will create a variable `variable.ground_speed_curve` that lives on the entity only while processing the animation controller for that frame. It will take the value of `query.ground_speed`, then remap it to between 0.2 and 0.7 based on the value of `query.ground_speed` going from 0.0 to 1.0It will play one animation walk that will blend from 0.0 to 1.0 as the ground speed increases from stopped to 2.3 m/s. The remap curve can have any number of entries. The animation controller will then play the entity-referenced `wiggle_nose` animations, followed by the `walk` animation, scaling the latter by the value of `variable.ground_speed_curve`



Back to top



User-Defined Script Example

This script will set foo to the result of the sine of query.life_time to later be used in the animation or animation controller.

Note: "pre_animation" tells the script to figure out the values of those variables once a frame, before animation occurs, so that the animation can use those values in their own formulas. If a variable didn't exist, it will create a new variable and its default value will be 0.0

Note in this example that because foo is equal to a sin wave, that its values will range from -1 to 1. This means that you will have a period from 0 to -1 to 0 where only "base_pose" will play and then an equal amount of time where Walk will play on top of base_pose as foo goes from 0 to 1 back to 0. Base_pose will have a blend value of 1.0.



Back to top

In definitions\entity\tiger.json:



Back to top







Channels (Rotation, Position, Scale)

The engine tracks the animation of rotation, position, and scale separately. Within a channel, one or more key frames are specified at arbitrary times, in seconds, from the start of the animation. If no key frames are specified, a single key frame is created at t=0.0 and all channel data is stored within that key frame.
Back to top

Entity Animation Format Examples

The json format for an animation is as follows. Note Matching the geometry format, units are in 1/16ths of meters.



Back to top

Getting Started

Adding Animations

Animation Controller

One needs to be able to control how animations are played, when, and how they interact with other animations. to group animations While a lot of this can be managed in the entity definition `scripts/animate` section, animation controllers give you the functionality of a state machine into states and control them as a block. Animations in an animation controller state can be animation controllers themselves, allowing for arbitrarily complex animation hierarchies.

Here's a sample animation controller

Back to top

Animations

At the beginning of each frame, the skeleton is reset to its default pose from its geometry definition and then animations are applied per-channel-additively in order. Note that the channels (x, y, and z) are added separately across animations first, then converted to a transform once all animations have been cumulatively applied.

Animation data can be either raw data:

By default, rotations are in degrees, in euler X-then-Y-then-Z format

Back to top

or a run-time interpreted script:



Back to top

Here is an example from quadruped.animation.json in the vanilla resource pack's animation folder:



Entity Definition

In order to define what animations an entity has, you must add both an `animations` and a `scripts/animate` section to an entity's entity definition file.

Here you can see the entity definition for pig.json:



Back to top

Note

Note: the walk animation for pig is the same for cows and sheep, and thus uses animation.quadruped.walk instead of defining its own. This means you will not see the move animation in the pig.json animation file either. If you would like to make a custom pig walk you can change this line to point to your custom animation.

Animations are specified as a short name, followed by their full resource name. The short name is used in animation controllers and the `scripts/animate` list, while the long name is used in the animations file.

In the `scripts/animate` section, you list the animations to play and in which order. You can either specify an animation directly, or specify a blend expression.
Back to top





Animation Hierarchy

Animations are channel based (rotation, position, or scale), and within that, they are key-framed:

EntityAnimation: animation name
__BoneAnimation[]: bone name to animation for this animation
____AnimationChannel[]: rotation, scale, or translation to animate
______KeyFrame[]: the value for the channel to be at, at a specific time

All of the above concepts are described in a detailed, bottom-up approach below
Back to top

Upgrade from v1.10 to v1.17.30

The major change with 1.17.30 is:
- Molang expressions inside transitions that contain capital letters are properly evaluated now. Strings inside such expressions are not forced to lowercase anymore and work as expected.
Back to top

Upgrade from v1.17.30 to v1.18.10

The major change with 1.18.10 is:
- Fixed an issue where animation controller events defined in the default state would get skipped if the controller immediately transitioned to another state.
Back to top

Upgrade from v1.18.10 to v1.18.20

The major change with 1.18.20 is:
- Molang expressions inside animation scripts for actor resource definition (pre_animation and initialize) that contain capital letters are properly evaluated now. Strings inside such expressions are not forced to lowercase anymore and work as expected.
Back to top

Upgrade from v1.7 Beta to v1.8

There have been few changes as we clean things up based on feedback and as we push the tech along the road map.To upgrade previous scripts, you'll want to do the following steps to all of your Molang scripts in the order listed:
1) entity.flags.foo --> query.foo
2) entity.member.foo --> query.foo
3) entity.foo --> variable.foo
4) params.foo --> global.foo
5) The general rule is that 'query' represents read-only values from the entity the script is running on, and 'variable' represents read-write data created by the user.
6) We've adopted snake_case for all names of things. You are welcome to use upper-case letters if you wish as we are case-insensitive, however we recommend snake_case in general.
7) Several variables previously set on mobs have been changed to use the query.foo format. Look through the updated list below to see what has been added and changed.
Back to top

Upgrade from v1.8 Beta to v1.10

The three major changes with 1.10 are
- the ability to have animations reference other animations in an arbitrarily deep hierarchy.
- the parameters section of animation controllers has been replaced with the `variables` section.
- in the entity definition file, animation controllers are now listed in the `animations` section, and a `scriptsnimate` section has been added to define which root animations to play.
The v1.8 file format is backwards-compatible with v1.10 so you don't _need_ to change anything (although we recommend refactoring your files in the spirit of v1.10 as there is a slight performance win with the new format, as well as it being simpler to understand.
Back to top



Key Frames

A key frame defines two values for a channel-specific transform to a specific bone at a specified time, one as time approaches the key frame time, and the second from that key frame time onwards.
As such, when interpolating between two key frames, one can define the slope of the animation curve in either a continuous or discontinuous manner.

Interpolation

Currently only linear interpolation is supported. Key frame "pre" and "post" settings allow control of the interpolation curve at any key frame.

Continuous Example

This example spins the bone "head" around the y axis 1 rotation in 1 second.
Note that because interpolation is linear, at .25 seconds the head will be rotated to 90 degrees.



Back to top

Discontinuous Example

Discontinuous just means that there won't be a smooth transition between key frames. It is useful if you want something to happen immediately.
This example scales the bone "head":
1. From 0 to 0.5 seconds (in the "pre" tag), the head bone is set to its normal scale of 1 in all dimensions [X, Y, Z]
2. At 0.5 seconds, the bone will instantly scale up to 2 times its normal size
3. From 0.5 to 1 second ("post"), the bone will re-scale back to its normal size of scale of 1 in all dimensions

Note In the larger example above of the file format, "pre" and "post" can also be defined by a Molang expression that calculates that value at runtime, allowing you to have a mathematically defined curve instead of being purely linear.



Back to top





Names

All names: animations, bones, states, etc, must all start with a letter and contain only alphanumerics, underscore, or period. It is recommended to use names in all lower-case
Back to top

Overview

The follows the current Minecraft JSON paradigms:
- Fields should be lower-case and use underscores (no spaces)
- All JSON files in the definitions directory and subtree will be read into and interpreted by the animation system
Back to top

Render Controllers

The Render Controller needs an identifier and needs to follow the format of "controller.render.". This name needs to match the name set in the Client Entity Definitions JSON.

Render Controllers are a way for the player to determine what renders on the entity. Players can set the geometry, materials, textures, and part visibility of the entity. In addition to setting the keys directly, players can use arrays to have the entity choose between different options.

Examples

Example Array for geometry from the sheep JSON

Example Array for materials from the spider JSON

Example Array for textures from the villager JSON

Example with color for tinting of parts from Armor 1.0 render controller JSON:

Example with is_hurt_color from Creeper render controller JSON:

Example with on_fire_color from Fireball render controller JSON:

Example with overlay_color from Wither Boss render controller JSON:

Example with part_visibility for turning on and off visibility of parts from Llama JSON:

Back to top

Note

NOTE: The arrays for Materials and Part visibility are applied in the order specified. Materials and Part visibility specified later in the file will override previous materials or parts.

Material array example from Horse render controllers. Saddle will override Mane, which will override TailA, etc.:

Back to top



Getting Started

To begin create a new folder named "render_controllers" in the root of the Resource Pack you want to add the new Render Controller JSON inside.

Example render controllers JSON for the ocelot

Back to top



Transforms

- Order of operations: vertices are translated, rotated, then scaled.
- Animation data is assumed to be hierarchical, and is applied to a bone by name matching the bone name in the animation data to the targeted geometry's skeleton.
- Not every bone needs to be animated
- You can animate bones that don't exist in the targeted geometry (missing bones are ignored).
- For each of scale, rotation, position, one can set the fields individually or uniformly with a single value. For example, these are equivalent.



Back to top