Best ender pearl angle

Hi all, back in 2023, I was googling what the optimal angle to throw an ender pearl was, but I was dissatisfied at the answers I got from Google. There were so many differing answers and answers providing only a range rather than an exact number; answers ranged from 35^\circ all the way to 40^\circ. So I did some independent research into it to find a more precise answer.

I never shared this project in public, but since discovering this technical forum, I feel this would be the perfect place to share my findings, and maybe even get some help for a discrepancy I encountered at the end.

This could be an interesting read if you are interested in math or programming. The level of math required to sufficiently understand this is a thorough understanding of algebra, and knowledge of trig functions.

** EDIT: This experiment is done with 0 player velocity (not running or jumping). The optimal angle would be different in these cases; see the first two replies.

Angle spoiler: The best angle is 37.9742431640625 ^_^

Problem setup

The pitch of a player is their line of sight with respect to the horizontal plane; it is the throwing angle of the pearl. The yaw of a player is their rotation about the vertical axis. Displayed below are common values for pitch and yaw; most notably, an upwards pitch corresponds to negative-valued angles.

We will assume a yaw of 0^\circ (travelling completely south), so that a pearl thrown at (0,0) could have its distance measured by simply reading the z-coordinate at landing. Our goal is to determine the pitch that achieves the furthest z-distance.

Below are the snippets of code that define the behavior of ender pearls, which we will be referencing. https://imgur.com/a/ender-pearl-code-java-1-16-1-Zp55wXl

Velocity

Initial velocity

First, Code A calls Code B to set the initial position of the pearl – this is not relevant yet until we run simulations of position, so we will disregard for now. Code D is then called, receiving the player’s pitch \theta_p and yaw \theta_y, and sets three constants:

\begin{align*} f &= -\sin(\theta_y)\cos(\theta_p) \\ f_1 &= -\sin(\theta_p) \\ f_2 &= \cos(\theta_y)\cos(\theta_p) \end{align*}

These are then are passed to Code E which computes the initial velocity vector as follows: (where v_p is the player’s velocity and \mathcal{N}(\mu, \sigma) the Gaussian distribution)

\begin{align*} v_{x0} &= v_{px} + 1.5 \left(\frac{f}{\sqrt{f^2 + f_1^2 + f_2^2}} + 0.0075 \cdot \mathcal{N}(0,1)\right) \\[10pt] v_{y0} &= v_{py} + 1.5 \left(\frac{f_1}{\sqrt{f^2 + f_1^2 + f_2^2}} + 0.0075 \cdot \mathcal{N}(0,1)\right) \\[10pt] v_{z0} &= v_{pz} + 1.5 \left(\frac{f_2}{\sqrt{f^2 + f_1^2 + f_2^2}} + 0.0075 \cdot \mathcal{N}(0,1)\right) \end{align*}

These velocities could be simplified:

  1. The randomness 0.0075\cdot \mathcal{N}(0,1) averages to 0 independent of pitch and yaw, so it is safe to ignore.
  2. The player velocity v_p is a constant, also independent of pitch and yaw, so it is safe to ignore. (Edit: this is wrong; it should be left in. still, the main math here still holds. it’d just take some additional algebra to incorporate the player velocity, which was done in the Github link later)
  3. Our assumption of yaw \theta_y = 0^\circ implies \sin(\theta_y)=0 and \cos(\theta_y) = 1, leading to:
\begin{align*} f &= 0 \\ f_1 &= -\sin(\theta_p) \qquad \text{(Unchanged)}\\ f_2 &= \cos(\theta_p) \end{align*}

Applying the above 1-3, we obtain a simplified initial velocity vector:

\begin{align} \begin{split} v_{x0} &= 0 \\ v_{y0} &= -1.5\sin(\theta_p) \\ v_{z0} &= 1.5 \cos(\theta_p) \end{split} \end{align}

Code D and E conclude, so Code A now calls Code F to begin computing velocity for subsequent ticks t.

Velocity at tick t

The velocity for subsequent ticks after tick 0 is determined recursively by Code F’s this.tick: In line 91, the next tick’s velocity is computed by multiplying the current velocity vector by 0.99 (provided the pearl isn’t in water) and subtracting 0.03 from the y-coordinate. We have:

\begin{align*} v_x(t, \theta) &= 0.99 \cdot v_x(t-1) \\ v_y(t, \theta) &= 0.99 \cdot v_y(t-1) - 0.03 \\ v_z(t, \theta) &= 0.99 \cdot v_z(t-1) \end{align*}

To enable further computation, we will compute closed forms for these recursions. We approach via method of unraveling. Starting with v_z:

\begin{align*} v_z(1) &= 0.99 \cdot v_{z0} \\ v_z(2) &= 0.99 \cdot v_z(1) \\ &= 0.99 \cdot \Big( 0.99 \cdot v_{z0} \Big) \\ v_z(3) &= 0.99 \cdot v_z(2) \\ &= 0.99 \cdot \Big(0.99 \cdot (0.99 \cdot v_{z0})\Big) \\ &\hphantom{a}\vdots \\ v_z(t) &= 0.99^{t}\cdot v_{z0} \\ &= 0.99^t \cdot 1.5 \cos(\theta_p) \end{align*}

he x-case follows exactly the same, and since v_{x0} = 0, we have v_x(t)=0. Now v_y:

\begin{align*} v_y(1) &= 0.99 \cdot v_{y0} - 0.03 \\ v_y(2) &= 0.99 \cdot v_y(1)- 0.03 \\ &= 0.99 \cdot \Big( 0.99 \cdot v_{y0} - 0.03 \Big) -0.03\\ v_y(3) &= 0.99 \cdot v_y(2) - 0.03 \\ &= 0.99 \cdot \Big( 0.99 \cdot \Big( 0.99 \cdot v_{y0} - 0.03 \Big) -0.03 \Big) - 0.03 \\ &\hphantom{a}\vdots \\ v_y(t) &= 0.99^{t}\cdot v_{y0} + \sum_{i=0}^{t-1} (-0.03)0.99^i \end{align*}

Using the formula for the sum of a finite geometric sequence, the right sum is -0.03 \left(\frac{1-0.99^t}{0.01}\right) = -3 + 3\cdot 0.99^t, so:

\begin{align*} v_y(t) &= 0.99^t \cdot v_{y0} - 3 + 3 \cdot 0.99^t \\ &= 0.99^t \cdot (v_{y0} + 3) - 3 \\ &= 0.99^t \cdot (3 - 1.5\sin(\theta_p)) - 3 \end{align*}

Let \theta=\theta_p for brevity. We have the velocity equations:

\begin{align*} v_x(t, \theta) &= 0 \\ v_y(t, \theta) &= 0.99^t \cdot \left(3 - 1.5\sin\theta\right) - 3 \\ v_z(t, \theta) &= 0.99^t \cdot 1.5\cos\theta \end{align*}

Position equations

The velocity functions enable us to find the position functions of a pearl. Since velocity is by definition meters traveled per tick, the distance traveled up to a tick t is the sum of velocities over all prior ticks – Code F line 75. We write this algebraically below, and use the sum of finite geometric sequences to simplify:

\begin{align*} d_z(t, \theta) &= \sum_{i=0}^{t-1} v_{z0} \cdot 0.99^i \\ &= v_{z0}(100 - 100\cdot 0.99^t) \\ &= 1.5\cos \theta(100 - 100 \cdot 0.99^t) \\ \\ d_y(t, \theta) &= \sum_{i=0}^{t-1}\left((v_{y0} + 3) \cdot 0.99^i - 3 \right) \\ &= (v_{y0} + 3)(100 - 100 \cdot 0.99^t) - 3t \\ &= (-1.5\sin\theta + 3)(100 - 100 \cdot 0.99^t) - 3t \\ \end{align*}

Note that these are not position equations – those would be obtained by summing initial position to the above distance equations. Assume the player is standing at (s_{x0},s_{y0},s_{z0}). Then per Code B, the initial position of the pearl is (s_{x0}, s_{y0} + 1.52, s_{z0}). Thus our position equations are:

\begin{align*} s_y(t, \theta) &= s_{y0} + 1.52 + (-1.5\sin\theta + 3)(100 - 100\cdot 0.99^t) - 3t \\ s_z(t, \theta) &= s_{z0} + 1.5 \cos\theta (100 - 100 \cdot 0.99^t) \end{align*}

Our goal is to find the pitch \theta that achieves the highest s_z.

Finding the best angle

To find the ending position for an angle \theta, we need to know the landing time T_\theta because s_z(T_\theta, \theta) would precisely be the ending position of the pearl. Let the landing ground y-level be s_{y0}, level with the player. Then T_\theta can be computed by solving s_y(t, \theta) = s_{y0} and rounding down to the previous tick (I forgot where I found this). We create the following procedure: for each angle \theta in [-90, 90], solve s_y(t, \theta) = s_{y0} and plug its answer into s_z; take the angle that produced the maximum s_z as the best throwing angle.

However, doing this procedure for all float angles in [-90, 90] would be computationally infeasible. Fortunately, due to the way Minecraft performs math, the range of angles is much more discrete, only taking on multiples of \displaystyle\frac{360}{65536}^\circ \approx 0.0055^\circ. We will call these significant angles as they are by the technical parkour community.

The significant angles of our working pitch range [-90,90] are given by \displaystyle\frac{360}{65536}k for -16384 \leq k \leq 16384, because \displaystyle\frac{360}{65536}(\pm 16384) = \pm 90.

Additionally, while the player’s angle \theta is stored as a float, at time of throwing, the pearl adopts the highest significant angle lower than \theta.

With the information presented, below would be our final algorithm:

for each k=-16384 to 16384:
\qquad Set \theta = \frac{360}{65536}k
\qquad Solve s_y(t, \theta) = s_{y0}, and round down the result; call this result T_\theta
\qquad Compute s_z(T_\theta, \theta)
Take the pitch with the highest s_z as the best angle

Solving for s_y(t,\theta)=s_{y0} cannot be done algebraically, so implementing that step would require usage of estimation methods, such as the Bisection method. We won’t discuss this here, but this was implemented in Python.

Example

Angle -40^\circ corresponds with k=-7282 since \frac{360}{65536}(-7282) = -40.0012207031 is the highest significant angle less than -40. Assume the player throws the pearl at yaw 0^\circ and from (0,0,0). To solve for the landing time T_\theta, we will solve s_y(t, -40.0012207031) = 0. Carry out the Bisection method to find that t=61.2433, so T_\theta = 61. Now compute the ending position:

\begin{align*} s_z(61, -40.0012207031) &= 1.5 \cos(-40.0012207031^\circ) (100 - 100 \cdot 0.99^{61}) \\ &= 52.66249862317 \end{align*}

Results

The algorithm was implemented in Python (ender-pearl-physics-analysis/script.py at master · Julia-1439/ender-pearl-physics-analysis · GitHub), yielding the following top 10 angles. They were also tested in-game, for which we received almost exact matches (we’ll discuss the discrepancy later).

Our predictions have a small margin of error, but on average, it is only 0.012 blocks of the actual distances. It’s currently unknown what causes this, but at least the sequence of errors is monotonic with the pitch, which means the cause is probably consistent across all angles.

Here is how -38^\circ compares to other commonly debated angles:

We obtain that the best pitch to maximize distance is \mathbf{-37.9742431640625^\circ}. Since the F3 menu displays pitch to only 1 decimal place, -38.0^\circ would be the best angle in practical settings. However, the level of precision obtained in this solution is exact to arbitrary decimal places, and it (hopefully!) settles the long standing question of best pearl angle. ***Edit: The best angle would actually depend on the initial player velocity, contrary to what I had thought. This is discussed in the first four replies. Though, -38.0 should still be the best angle for throwing while standing still and not jumping.

Julia_1439

2 Likes

I believe the optimal angle is affected by the player’s initial velocity, as it affects drag and the time it takes for the pearl to land. I used the program to calculate the optimal pitch for jump throwing, which is -31.4373779296875 with a distance of 67.14682552512888 (initial y position 1.94 and y velocity 0.42), and for sprint jump throwing, which is -33.1512451171875 with a distance of 77.75947629748147 (initial y position 1.94, y velocity 0.42, and z velocity 0.2), though I have not tested these in-game.

1 Like

Thank you very much for the reply! I’m surprised you got the code working and tweak it enough to make those findings. I hadn’t looked at that code in years and it was kind of spaghetti. Anyways, I did modify the code to incorporate a custom initial velocity and changed it to a Github link.

I validated your findings and got the same numbers, with both jump and jump-sprint. I made a mistake thinking that initial player velocity didn’t matter. I’ve noted this in an edit.

I tested the jump and jump-sprint ingame and these were the closest distances I got:

jump only

jump-sprint

Seems to be less than what we predicted…

Oh I didn’t actually test it with exact velocities. It was some quick in-game testing without any fancy commands. I just wanted to show that I was able to achieve distances that were in the ballpark of our predictions. I’m not sure how to test it with exact velocities, though I haven’t looked much into it.

Me if i was smart enough to understand this: Oh wow thats so cool!
Me since i am not smart enough: I think this is really cool, but i cant say for certain!