smish.dev
ball_simulation_3

This post aims to describe an accurate model of the physics behind the collisions of Rocket League, so that players and bot developers might better understand precisely what happens when the car and ball make contact.

Although these notes are presented on this personal website, this work was a collaboration with Nevercast and tarehart (both members of the RLBot community). Additionally, I also want to express my thanks to Bakkes for developing tools that greatly simplified the data collection process for this analysis.

Hitboxes and Collision Detection

Rocket League doesn't use the actual car's geometry to determine when collisions take place, instead they use oriented bounding boxes (OBBs) for each preset type:

Although this geometry doesn't really match the car very well, it is convenient from a programming perspective because it is inexpensive to perform intersection tests on this simple shape. In particular, we can determine if a sphere is contacting the oriented bounding box by first finding the point on the OBB that is closest to the sphere's center, and then check if the distance between those points is less than the radius.

For a general shape, it can be pretty challenging to find the point on that shape that has the least distance to another point of interest. Fortunately, the orthogonality of the face normals on the OBB make it so we can find that nearest point in only a few lines of code.

Here's one possible implementation of a way to find that nearest point:

Detailed information about hitbox dimensions and offsets for each preset type can be found here, courtesy of halfwaydead. Additionally, his video on hitboxes (and everything else on his channel) is also highly recommended.

Now that we have a way to detect when a collision happens, how does it affect the trajectory of the ball?

Relevant Physics of Rigid Body Collisions

If a car collides with the ball, we need to know the following information to predict the outcome of the collision:

Some other useful notation:

A symbol's subscript will be used to distinguish between quantities belonging to the car and ball (either 'c' for car or 'b' for ball). e.g. Θc will be the car's orientation matrix, ωb will be the ball's angular velocity, and so on. Symbols in bold represent vectors or matrices (e.g. 1 is the identity matrix, not the number 1), and all other symbols are scalars.

When objects collide, they exert (equal and opposite) forces on each other to prevent interpenetration. In general, there can be many points of contact (each with its own force), but the problem we care about is simple: a sphere hitting a box. In this case, the contact can be reasonably approximated by a force applied a single point. If we knew that force, F, was applied to a rigid body at point p for a duration Δt, then the rigid body would respond in the following way (where quantities with a tilde are the post-collision values, and J=FΔt):

(1){v~=v+m1Jω~=ω+I1[(px)×J]=ω+I1LJ

So, the velocity change only depends on the impulse itself, not where it is applied. In contrast, the change in angular velocity cares about where that force is being applied, and the matrix L represents the "lever arm".

All that remains is to find an expression that tells us how to compute the appropriate value of J and we can use the equation above to figure out what the ball will be doing after the collision.

In Rocket League, this J is actually made up of two separate contributions: one from the game's underlying physics engine, and one that Psyonix added to make the game more predictable and fun. The following sections below describe how to calculate those different contributions.

Impulse from the Physics Engine

This impulse from the physics engine is modeled as coming from an inelastic rigid-body collision with Coulomb friction.

Intuitively, the 'inelastic collision' part of the model means that the impulse J will be determined such that the post-collision surface velocities at p of the two bodies are the same. The surface velocity, V at p depends on the object's velocity, as well as how fast it is spinning:

(2)V=v+ω×(px)=vLω

So, the inelastic collision model demands that ΔV~V~cV~b=0, which when applying equations (1) and (2) gives us and expression in terms of the unknown impulse J:

(1)0=ΔV~=V~cV~b=[v~cLcω~c][v~bLbω~b]0=[(vc+Jmc)Lc(ωc+Ic1LcJ)][(vbJmb)Lb(ωbIb1LbJ)]

Group similar terms and solve for J:

(2)0=([vcLcωc][vbLbωb])ΔV+([1mc+1mb]1LcIc1LcLbIb1Lb)M1J

So, when the dust settles, we are left with a 3 by 3 system of linear equations. This system can be solved to determine the impulse:

(3)J=MΔV

where the matrix M could be interpreted as the reduced mass matrix for this problem.

The Coulomb friction model says that the maximum allowable frictional force for the collision is proportional to the normal component of J. We call the constant of proportionality the 'coefficient of friction' and represent it by the symbol μ. Quantitatively, the constraint is simply:

(4)JμJwhere{J=(Jn)nJ=JJandn=pxbpxb

n is the unit contact normal direction (depicted below), and J,J are the perpendicular and parallel parts of J, respectively.

This constraint is enforced by taking the impulse that comes from the inelastic collision model above, and rescaling J if it exceeds the maximum acceptable value:

(5)J:=J+min(1,μJJ)J

I hope to release a complete reference implementation of this procedure in C++ soon.

Impulse from Psyonix

In order to tune the feel and control of the collisions in Rocket League, Psyonix applies an additional impulse to the center of ball (here pxb) that is more predictable than the one directly from the physics engine.

This impulse is simple to describe, as it is given explicitly in terms of only the positions and velocities between the car and ball. Its value is given by:

(6)J=mbΔvs(Δv)n

where Δvvbvc, and the contact normal n can be computed by transforming the vector from the car to the ball in the following way:

and the scaling function s(Δv) is depicted below:

Oddly enough, this part of the collision violates Newton's 3rd Law of Motion, since Psyonix applies this impulse to the ball without applying an equal and opposite impulse to the car. So, each time you hit the ball in Rocket League, momentum is not conserved!

Example Predictions and Observations

Consider the simple situation where a car approaches the ball, jumps, and dodges forward to make contact (visualization of actual game data, not a simulation):

This scenario was repeated several times by a bot, with different initial separations between the car and ball. It timed the dodges such that when the car contacts the ball, each run has identical velocity and angular velocity, but different orientation. The figures below are closeups of the moment of contact for each run, along with the exact velocity change of the ball compared to the values predicted by the approach described in this article.

To put these values in perspective, the weakest hit in this set traveled for about 2500 units before hitting the ground again. The strongest hit was 40% faster, and traveled 5200 units (over twice as far).

So, even for a test where almost everything was constrained to be identical, varying the orientation by a few degrees can make a huge difference in the outcome of the collision.

Final Thoughts

This model has been tested on a variety of different types of hits, including dribbling, wall shots, aerial hits, and dodge shots. For these examples, the error in the predictions is small enough to be negligible for practical purposes (on the order of 0.1% to 3% error).

This model is not suitable for wheel hits or pinches!