Some equation governing Minecraft physics engine and the way to get to it
Minecraft physics engine update physics properties every ticks, the goal of this document is to understand how the physics engine works with various Minecraft objects and develop equation to predict the trajectory of entities. We will use most common units used in Minecraft to describe the dynamic of objects.
The distance unit will be the meter, where 1 meter is the width of a block.
The time unit will be the tick, where 1 tick = 1/20 seconds.
Because the time is discrete we will avoid Newtonian mechanic equations which usually require continuous time. Using these equation will lead to huge inaccuracy.
We will first need to understand what velocity and acceleration are. Basically velocity is the rate of change of position and acceleration is the rate of change of velocity, which can be translated into equations that you may have already encountered, let's split it into the equation used with discrete and continuous time :
Continuous | Discrete | |
---|---|---|
Velocity | ||
Acceleration |
In Minecraft physics engine, the standard timestamp between updates is 1 tick, so
These are the two expression we will be using for our equations later on.
Let's talk about forces and illustrate how they work with Newtonian mechanic equation (even if they won't work to predict game physic, they are useful to understand what forces are). The Newton's second law of motion tells us that forces applied on an object are proportional to acceleration of this object (the proportionality constant being mass) :
There is no such thing as mass in Minecraft, so we will considere that acceleration are equal to the sum of all the forces (there is obviously a unit error here, but we can consider forces to be the same as acceleration because mass isn't a thing here).
Let's apply that to the trajectory of projectiles. First of all we will need to find all the forces applied to a projectile.
We can find these information on the Minecraft wiki (here), there is only two forces here, one strictly vertical: gravity, and the second one is the drag, being applied on all direction. We will use the cartesian coordinate system to describe projectiles dynamic (x, y, z, y being the vertical axis on which gravity act). x and z axis being equivalent, we will only describe motion on x axis.
Gravity is the easiest of the two forces, it is denoted as the "acceleration" on the Minecraft wiki, we will call it
Drag (which can be interpreted as the air resistance, even if it doesn't act exactly the same), is not constant, it is proportional to the velocity of the object, let's call it
As we said earlier, there is only one force here : the drag, so we have the following equality :
From
By a change of variable we get :
Now let's try to express
Or even that :
Let's chose
That's the final expression for velocity on the x (or z) axis.
This time we have two forces, gravity and drag, so we have this expression for acceleration :
We then get :
With the same change of variable as earlier we get :
We also have :
That's the final expression for the velocity on the y axis.
From this relation
With
With the formula for the sum of geometric series we get :
This is the final expression for the position of the object on the x axis
We will apply the same relation as before, but replacing the horizontal velocity with the vertical one :
We obviously get the same summation :
This is the final expression for the position of the object on the y axis
Let