Skip to content
AzureDoom edited this page Sep 16, 2022 · 7 revisions

Molang

Molang is a simple but powerful expression-based language that can create very complex and powerful animations. It has a learning curve, but once you master it it becomes a very useful tool in your animation toolset.

Molang allows you to type math expressions into keyframe values instead of just numbers. For example, you could type 5 * 4 into a scale keyframe, and it would evaluate to 20. You can also do much more complex things using math functions like math.sin, math.cos, and math.abs. Read about all the math functions on the Bedrock Wiki.

GeckoLib 3.0.0 supports Molang, and has several useful queries.

Supported Queries

  • query.anim_time
  • query.actor_count
  • query.time_of_day
  • query.moon_phase
  • query.distance_from_camera
  • query.is_on_ground
  • query.is_in_water
  • query.is_in_water_or_rain
  • query.health
  • query.max_health
  • query.is_on_fire
  • query.on_fire_time
  • query.ground_speed
  • query.yaw_speed

Examples

Horizontal sine

In this example, the 200 is used as a modifier for the speed of the cube, and the 10 is used to control how far it moves.

Position:

  • X: 0
  • Y: 0
  • Z: math.sin(query.anim_time * 200) * 10

!circle{:width=350}

Circle

Position:

  • X: 0
  • Y: math.cos(query.anim_time * 200) * 10
  • Z: math.sin(query.anim_time * 200) * 10

!circle{:width=350}

Bouncy Cube

Position:

  • X: 0
  • Y: math.abs(math.sin(query.anim_time * 500) * math.exp(-0.5 * query.anim_time)) * 10
  • Z: 0

!cube{:width=350}

Crystal

Rotation:

  • X: math.sin(query.anim_time * 100) * 150
  • Y: math.cos(query.anim_time * 100) * 150
  • Z: math.sin(query.anim_time * 100) * 150

!crystal{:width=350}

Arc

Position:

To arc a bone between two points, see this article

In this example, the bone is moving between from (-10, 0) to (10, 0) and uses (0, 15) as it's height control point. It will never reach (0, 15).

  • X: Math.lerp(-10, 10, query.anim_time)
  • Y: Math.lerp(Math.lerp(0, temp.control_height, query.anim_time), Math.lerp(temp.control_height, 0, query.anim_time), query.anim_time)
  • Z: 0

Preview Variables:

temp.control_height = 50;

!arc{:width=350}

Human Idle

Left Arm:

  • X: Math.cos(query.anim_time * 150 +75) * -15
  • Y: 0
  • Z: 0

Right Arm (Rotation):

  • X: Math.cos(query.anim_time * 150 +25) * 15
  • Y: 0
  • Z: 0

Body (Position):

  • X: 0
  • Y: Math.cos(query.anim_time * 100) * 0.5 -0.5
  • Z: 0

Head (Rotation):

  • X: Math.cos(query.anim_time * 100 -50) * -5
  • Y: 0
  • Z: 0

!idle{:width=350}

Try out this model here!

Controlling Animation Speed

Position:

To control the speed of an animation, define your own variable. In this example, we'll name it anim_speed. Then, either set it to a predefined value, like 2. Then in code you can set this value using GeckoLibCache.getInstance().parser.setValue("anim_speed", 2); Simply set this in your renderer, and it will get updated every frame before being animated. In this example, the anim_speed variable is updated dynamically to match the query.anim_time field, effectively making the animation speed up over time.

  • X: Math.lerp(-30, 30, query.anim_time * anim_speed)
  • Y: Math.lerp(Math.lerp(0, temp.control_height, query.anim_time * anim_speed), Math.lerp(temp.control_height, 0, query.anim_time * anim_speed), query.anim_time * anim_speed)
  • Z: 0

Preview Variables:

temp.control_height = 80;
anim_speed = query.anim_time / 2;

!arc{:width=350}

Read about what all these queries do on the wiki.

If GeckoLib is missing a query that you need, ask us in the discord.

Table of Contents

Geckolib 3
Geckolib 4

Hosted By: Cloudsmith

Package repository hosting is graciously provided by Cloudsmith.

Cloudsmith is the only fully hosted, cloud-native, universal package management solution that enables your organization to create, store and share packages in any format, to any place, with total confidence.

Clone this wiki locally