Movement Formulas

From Minecraft Parkour Wiki
Revision as of 23:58, 24 August 2020 by MCPK (talk | contribs)
Movement formulas applied to a 3b jump.

The Player's movement can be accurately calculated with sequences.

The following formulas come from analyzing the game's source code.


Note that these formulas are not exact, due to how floats are computed. When used for calculations, only the first 4-6 decimals should be considered accurate. For a completely accurate simulation, you would need to replicate the source code.


In this article, we're only considering standard movement, and ignoring mechanics specific to certain blocks.


You will find further documentation of movement physics in these articles:


Note: Minecraft's coordinate system is orientated differently: 0° points towards "positive Z", and 90° points towards "negative X". We choose to work in the standard coordinate system to make calculations more intuitive. If need be, we can simply invert the X axis to match Minecraft's coordinate system.


Vertical Movement

Jump Formula


If , is set to 0 instead.
In 1.9+, it's compared to 0.003 instead.


Notes

  • corresponds to the initial jump motion.
  • is increased by 0.1 per level of Jump Boost
  • Terminal velocity is -3.92 b/t
  • When the Player collides vertically with a block, is set to 0.


Vertical Position

To get the position on a given tick, you simply need to sum


Jump duration

The duration of a jump is the number of ticks between jumping and landing.
It also corresponds to the period (in ticks) of that jump's cycle when performed repeatedly.
Airtime is linked to the notion of Tiers.
Description Airtime
Flat Jump 12 t
3bc Jump 11 t
+0.5 Jump 10 t
+1 Jump 9 t
2.5bc Jump 6 t
2bc Jump 3 t
1.8125bc Jump 2 t


Source code

from EntityLivingBase

/* Code unrelated to vertical movement is cut out */

protected float getJumpUpwardsMotion(){
    return 0.42F;
}


protected void jump()
{
    this.motionY = this.getJumpUpwardsMotion();
    if (this.isPotionActive(Potion.jump))
    {
        this.motionY += (this.getActivePotionEffect(Potion.jump).getAmplifier() + 1) * 0.1F;
    }
    this.isAirBorne = true;
}


public void moveEntityWithHeading(float strafe, float forward)
{
    ... /* also moves the player horizontally */

    this.motionY -= 0.08;
    this.motionY *= 0.98;
}


public void onLivingUpdate()
{
    if (this.jumpTicks > 0)
        --this.jumpTicks;

    if (Math.abs(this.motionY) < 0.005D)
        this.motionY = 0.0D;


    if (this.isJumping)
    {
        ... /* different if in water or lava */

        if (this.onGround && this.jumpTicks == 0)
        {
            this.jump();
            this.jumpTicks = 10; //activate autojump cooldown (0.5s)
        }
    }
        
    else
    {
        this.jumpTicks = 0; //reset autojump cooldown
    }

    ...
    
    this.moveEntityWithHeading(this.moveStrafing, this.moveForward);
}

Horizontal Movement

Horizontal Movement is a bit more complex than Vertical Movement, as it relies on many more factors: Player Actions, Direction, and Ground Slipperiness.

On every tick, the game does these three steps:

  1. Acceleration is added to the Player's velocity.
  2. The Player is moved (new position = position + velocity).
  3. The Player's velocity is reduced to simulate drag.

We'll start by introducing Multipliers in an effort to make formulas more readable.


Multipliers

Movement Multiplier (See 45° Strafe)


Failed to parse (unknown function "\begin{Bmatrix}"): {\displaystyle M_{t} = \begin{Bmatrix}1.3 & \textrm{Sprinting} \\ 1.0 & \textrm{Walking}\\ 0.3 & \textrm{Sneaking}\\ 0.0 & \textrm{Stopping} \end{Bmatrix} \times \begin{Bmatrix}0.98 & \textrm{Default}\\ 1.0 & \textrm{45° Strafe} \\ 0.98 \sqrt{2} & \textrm{45° Sneak} \end{Bmatrix}}


Effects Multiplier (See Status Effects)


Failed to parse (syntax error): {\displaystyle E_{t} = (\underset{Decreases \; by \; 15\% \; per \; level \; of \; Slowness}{\underset{Increases \; by \; 20\% \; per \; level \; of \; Speed}{\underbrace{\left ( 1 + 0.2\times Speed \right ) \: \times\: \left ( 1 - 0.15\times Slowness \right )}}} \geq 0}


Slipperiness Multiplier (See Slipperiness)



Linear Formulas

These simplified formulas only apply to linear movement (no change in direction).
While this condition might seem very restrictive, these formulas are very useful to analyze conventional jumps and momentum.
We'll later expand on these formulas by including angles.


Ground Speed:
Failed to parse (syntax error): {\displaystyle V_{H,t} = \underset{Momentum}{\underbrace{\underset{ }{V_{H,t-1} \times S_{t-1} \times 0.91 }}} \: + \: \underset{Acceleration}{\underbrace{0.1 \times M_{t} \times E_{t} \times \left (\frac{0.6}{S_{t}} \right )^{3}}} }


Jump Speed:
Failed to parse (syntax error): {\displaystyle V_{H,t} = \underset{Momentum}{\underbrace{\underset{ }{V_{H,t} \times S_{t-1} \times 0.91 }}} \: + \: \underset{Acceleration}{\underbrace{0.1 \times M_{t} \times E_{t} \times \left (\frac{0.6}{S_{t}} \right )^{3}}} + \underset{Sprintjump \; Boost}{\underbrace{\begin{Bmatrix}0.2 & \textrm{Sprinting}\\ 0.0 & \textrm{Else}\end{Bmatrix} }}}


Air Speed:
Failed to parse (syntax error): {\displaystyle V_{H,t} = \underset{Momentum}{\underbrace{\underset{ }{V_{H,t} \times S_{t-1} \times 0.91 }}} \: + \: \underset{Acceleration}{\underbrace{\underset{ }{0.02 \times M_{t}}}} }

Complete Formulas

Let's introduce two more variables:
  • , The player's Direction in degrees (defined by their inputs and rotation)
  • , The player's Facing in degrees (defined by their rotation only)


In reality, angles aren't as simple as that, as there are a limited number of significant angles (see Facing and Angles).

For the purpose of simplicity, we'll assume and are not affected by yaw-to-angle conversion.


Ground Velocity:
Failed to parse (syntax error): {\displaystyle V\displaystyle _{X,t} = \underset{ }{V\displaystyle _{X,t-1} \times S_{t-1} \times 0.91 } \: + \: 0.1 \times M_{t} \times E_{t} \times \left (\frac{0.6}{S_{t}} \right )^{3} \times \sin (D_{t}) }
Failed to parse (SVG (MathML can be enabled via browser plugin): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle V\displaystyle _{Z,t} = \underset{Momentum}{\underbrace{\underset{ }{V\displaystyle _{Z,t-1} \times S_{t-1} \times 0.91 }}} \: + \: \underset{Acceleration}{\underbrace{0.1 \times M_{t} \times E_{t} \times \left (\frac{0.6}{S_{t}} \right )^{3}}} \times \cos (D_{t}) }
Jump Velocity:
Failed to parse (syntax error): {\displaystyle V\displaystyle _{X,t} = \underset{ }{V\displaystyle _{X,t-1} \times S_{t-1} \times 0.91 } \: + \: 0.1 \times M_{t} \times E_{t} \times \left (\frac{0.6}{S_{t}} \right )^{3} \times \sin (D_{t}) + \begin{Bmatrix} 0.2 & \textrm{Sprinting}\\ 0.0 & \textrm{Else}\end{Bmatrix} \times \sin (F_{t}) }
Failed to parse (syntax error): {\displaystyle V\displaystyle _{Z,t} = \underset{Momentum}{\underbrace{\underset{ }{V\displaystyle _{Z,t-1} \times S_{t-1} \times 0.91 }}} \: + \: \underset{Acceleration}{\underbrace{0.1 \times M_{t} \times E_{t} \times \left (\frac{0.6}{S_{t}} \right )^{3}}} \times \cos (D_{t}) + \underset{Sprintjump \; Boost }{\underbrace{\begin{Bmatrix} 0.2 & \textrm{Sprinting}\\ 0.0 & \textrm{Else}\end{Bmatrix} \times \cos (F_{t})}} }


Air Velocity:
Failed to parse (syntax error): {\displaystyle V\displaystyle _{X,t} = \underset{ }{V\displaystyle _{X,t-1} \times S_{t-1} \times 0.91 } \: + \: 0.02 \times M_{t} \times \sin (D_{t}) }
Failed to parse (syntax error): {\displaystyle V\displaystyle _{Z,t} = \underset{Momentum}{\underbrace{\underset{ }{V\displaystyle _{Z,t-1} \times S_{t-1} \times 0.91 }}} \: + \: \underset{Acceleration}{\underbrace{\underset{}{0.02 \times M_{t}}}} \times \cos (D_{t}) }

Stopping Conditions

Horizontal speed is set to 0 if the Player hits a wall, or if the speed is considered to be negligible.


Wall Collision:
If the player hits a X-facing wall, then is set to 0 and the Player is placed against the wall.
If the player hits a Z-facing wall, then is set to 0 and the Player is placed against the wall.


Negligible Speed:
If before adding acceleration, momentum is cancelled and only the acceleration is left.
If before adding acceleration, momentum is cancelled and only the acceleration is left.
In 1.9+, they are compared to 0.003 instead.


Source Code

[...]



Non-Recursive Formulas

Since arithmetico-geometric sequences have explicit formulas, we can build non-recursive formulas to calculate simple but useful notions, such as the height of the player on any given tick, or the distance of a jump in terms of the player's initial speed and the duration.

Numeric approximations are given with 6 digits of precision.


Definitions:

  • is the player's initial speed (speed on , before jumping)
  • is the number of ticks considered (ex: t=12 on flat ground, see Jump Duration)
  • is the movement multiplier after jumping (1.3 for 45° sprint, 1.274 for normal sprint...)

Vertical Movement (jump) [Pre-1.8]

Vertical speed after jumping ()

num. approx:

Relative height after jumping ()

num. approx:

Vertical Movement (jump) [1.9+]

Vertical speed after jumping ()

num. approx:

Relative height after jumping ()

num. approx:



Horizontal Movement (instant jump)

Horizontal speed after jumping ()

45° sprint:
reg. sprint:

Jump distance ()

45° sprint:
reg. sprint:


Horizontal Movement (delayed jump)

Horizontal speed after jumping ()