Skip to content
This repository has been archived by the owner on Nov 19, 2018. It is now read-only.

Vertical entity movement

ecx86 edited this page Dec 31, 2015 · 8 revisions

Analysis is based on the decompiled source of the vanilla b1.7.3 client. The following describes the vertical motion of an entity only.

Terms

Velocity will refer to the vertical velocity of a player in meters (blocks) per tick. This should be added to the player's position at a specific time during each tick, after certain processes and before others.

1 tick will refer to the period of time that is equivalent to 1/20th of a second.

On tick

The processes described below should be applied sequentially each tick an entity is updated.

Water Motion

If the entity is in water, this is a special case. Only apply the following steps:

  1. Apply motion: Offset the entity position by its vertical (y) velocity.
  2. Leaving water: If a player is leaving the water, set the player's velocity to +0.3 meters per tick go directly to step 5.
  3. Water friction: Multiply the vertical velocity by a factor of 0.8.
  4. Gravity: Add -0.02 meters per tick to the vertical velocity.
  5. Stop do not perform further calculations.

A player is considered "leaving water" and gets a vertical boost if all of the following conditions are met:

  • The player is colliding horizontally.
  • The player would be in a liquid if his position was offset by the vector <velocity x, velocity y + 0.6, velocity z>

Lava motion

If a player is not in water but is in lava, these steps are performed. The steps are the same as for water motion, except the friction factor is 0.5.

Normal Motion

Apply these steps if an entity is not in water nor lava.

  1. If on ladder: If the vertical velocity is less than -0.15 meters per tick clamp it to -0.15 meters per tick.
  2. If on ladder: If the entity is sneaking and the vertical velocity is less than 0, set the vertical velocity to 0.
  3. Offset the entity's position by its current velocity.
  4. If on ladder: If the entity is colliding horizontally set the entity's vertical velocity to +0.2 meters per tick.
  5. Gravity in air is -0.08 meters per tick squared, so add -0.08 meters per tick to the vertical velocity.
  6. The normal air friction factor is 0.98 in air, so multiply the vertical velocity by 0.98.

Note that lateral (x/z) motion is also being calculated during these steps, both before and after the offset position steps.

Knockback

If an entity is knocked back, perform these steps:

  1. Add 0.4 meters per tick to the vertical velocity.
  2. If the vertical velocity is now over 0.4 meters per tick, clamp it to 0.4 meters per tick.

Apply these steps as soon as the entity is attacked and damaged.

Jumping

If an entity jumps (presses jump key), perform these steps:

  1. If the entity is in water or lava, add 0.04 meters per tick to the vertical velocity.
  2. If the entity is on ground, set 0.42 meters per tick to the vertical velocity.

Perform these steps before those described in "On Tick".

Clone this wiki locally