Mario Kart Maths: Green Shell Ballistics

There’s something particularly upsetting about being hit by a green shell.

greenshellRed shells at least have the decency to announce their arrival. Red shells also have integrity enough to admit they are actually being steered: there is a prevailing belief that the nominally unguided green shells are in fact deflected towards players after recoiling from a wall. This unconfirmed phenomenon is nicknamed ‘smart-bouncing’, and may (along with a colossal hitbox) go some way to explaining why it’s so easy to hit yourself with a green shell.

In the chaos of the midfield, it’s often impractical to keep checking behind you for incoming green shells. So how best to avoid impact? In this post, I’ll present the results of a numerical model that predicts where along the track you are most likely to be hit.

\

The purpose of the model is to simulate a cart being bombarded by a large number (~105) of green shells launched with a narrow distribution of initial positions and velocities. The probability of the cart being hit is calculated by taking the ratio of the number of green shells that hit the cart to the number of shells fired. This calculation is carried out for a range of cart positions. Here’s how the program works.

shell_diagramConsider a straight track situated in the xy plane, as pictured in the diagram to the right. The edges of the track coincide with the lines x=\pm\frac{1}{2}. Somewhere on the track is a cart (depicted as a red circle) of radius r_c with coordinates \left(x_c,y_c\right), constrained by |x_c|\le\frac{1}{2}-r_c and y_c\ge 0.

The program spawns a shell of radius r_s somewhere on the line y = 0. The shell’s x-coordinate x_s is chosen from a normal distribution zero mean and a standard deviation \sigma(x_s) of about 0.5. The normal distribution is chosen because most players will drive somewhere close to, but not exactly along, the centre of the track, and so the shells they launch will have a narrow distribution of positions.

A line connecting the shell to the cart is then drawn (rendered in red). The program then generates a ‘deflection angle’ \Delta\theta, once again chosen with zero mean and some standard deviation \sigma(\Delta\theta). The line segment connecting the shell and cart is rotated about the shell through this angle, and the shell is subsequently launched along this line (drawn in green). This is done to ensure the attacker only has finite accuracy: the larger \sigma(\Delta\theta), the less accurate they are.

With the initial position and velocity of the shell specified, the program can subsequently solve for the shell’s trajectory. The shell is assumed to experience zero acceleration for all time, apart from when it encounters either of the track edges, in which case its x-component of velocity is reversed (that is, we neglect smart-bouncing). The shell’s coordinates are propagated through time until i) it collides with the cart or ii) its y-coordinate exceeds y_c+r_s+r_c (i.e. it is guaranteed to have missed).

The procedure above is repeated N = 100 000 times. The hit rate is calculated by dividing the total number of successful hits by N. The program then shifts the cart’s x-coordinate by some small amount, and the entire process repeats. The result is a hit rate curve describing how likely you are to be hit depending on how far along the track you are.

The parameters used for this models were: y_c = 3, r_c = 0.050 and r_s = 0.075. The graph below displays the hit rate as a function of x_c. The number next to each curve denotes \sigma(\Delta\theta).

hit_rate

We first notice that the greater \sigma(\Delta\theta), the lower the average hit rate; this should not be surprising. We also see that, for high accuracy, there is a very little variation of the hit rate with x_c. However, something interesting happens as the attacker’s accuracy decreases: sharp maxima appear a roughly midway between the track centre and its edges. What’s going on here?

The diagram below shows traces of shells fired at a cart in three positions from left to right: at the track centre, midway between the centre and the edge, and at the edge. White rays indicate those shells that miss the cart, green those that hit. We have set \sigma(x_s) to zero for clarity.

shell_raysThe leftmost pane shows traces of shells fired at a cart on the track centre. This defines our baseline hit rate, with no complications being caused by the track edges.

The central pane shows traces of shells fired at a cart midway between the track centre and edge. The traces make it clear that a greater percentage of the shells fired collide with the cart. Why? Because it is now possible for shells that would otherwise miss the cart to collide with the track edge before landing a successful hit.

The rightmost pane shows traces of shells fired at a card at the track edge. Conversely, the hit rate here is fractionally diminished, for the following reason: shells that would otherwise strike the cart on its left-hand side are deflected by the track edge, and narrowly miss the cart on its right-hand side.

This discussion provides the intuition as to why there should exist maxima in the hit rate curve. Can we make a quantitative prediction of where exactly these maxima occur? The central pane about shows that, for a cart between the track centre and one of the maxima, there is a ‘shadow’ in the angle distribution where shells pass between the cart and the track edge; shells launched with smaller \Delta\theta are able to hit the cart directly, while those with larger \Delta\theta rebound from the wall first. As the cart moves closer to the maximum, you can imagine this shadow closing up, eventually reaching the point where a shell can only just pass between the cart and the track edge. If the cart moves even a little nearer the track edge, the shadow suddenly vanishes. This must be when the hit rate rushes up to its maximal value.

If you’re so inclined, you can find the precise value of x_c at which a shell is only just able to pass between the cart and the track edge. The value is a solution of the quadratic equation

\left(y_c^2 - r_s^2\right)x_c^2+ \left(y_c^2 + r_s\left[r_s + r_c\right]\right)x_c+\left(\frac{1}{4}\left[y_c^2 - \left(r_s + r_c\right)^2\right]-\left[2r_s + r_c\right]^2 y_c^2\right)=0.

You can show that, if y_c\gg r_s, r_c, the solution reduces to

x_c\approx\frac{1}{2}-\left(2r_s + r_c\right).

Simply put, this says that the most dangerous place to drive is where your cart’s edge is exactly one shell’s diameter from the track edge. These positions have been indicated on the hit rate graph by the vertical dashed lines; you can see they predict the locations of the maxima very well!

\

So, the moral of the story is this: driving down the middle of the track is actually not too bad a strategy if you want to avoid unseen green shells. Generally, the nearer the edge of the track you are, the more likely you are to be hit by rebounding shells. Of course, you can also invert this reasoning, and conclude that, if you are armed with green shells, you should wait for the person in front of you to drift towards the edge of the track before firing.

I hope this advice serves you well. Happy karting!

Return to top

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s