smish.dev
ball_simulation_2

In a previous post, we looked at a physical model for how the ball behaves in Rocket League. This model accurately described what happens when the ball hits an obstacle with a given surface normal, but without a way to find these collisions (and their surface normals) it was not very useful.

This post describes how we can use meshes taken from Rocket League to detect collisions, and calculate the surface normal required by our bouncing model from earlier.

Mesh Files

The RLBot community has collision meshes for the map corners, goals, and cylindrical ramps on the sides of the field. I've put these together into the mesh above, and it can be downloaded here.

Naive Collision Detection

With the mesh above, we can read the 8028 triangles individually, and check sphere-triangle intersection tests on each of them in order to find all possible faces that might be in contact with the ball.

A basic implementation of the necessary triangle-sphere intersection tests needed to accomplish this is given below:

Let's try this naive approach on a benchmark problem that randomly generates spheres and checks each triangle for intersection:

Although this can improve the fidelity of our ball predictions, spending an entire millisecond to see if the ball hits the mesh is way too expensive. We might want to predict ahead a few hundred time steps to plan a bot's actions, but that really isn't possible with this naive approach.

Bounding Volume Hierarchies

One way to improve the performance of these geometric queries is to use a spatial acceleration structure. The basic idea behind this is to analyze the geometry of our mesh, and systematically group sections that are close to each other. Then, when we perform a query (i.e. find which parts of the mesh intersect an given object), we can cull entire sections of the mesh at a time, quickly zeroing in on only nearby geometry.

I highly recommend reading through the 3 part series on BVH generation on NVIDIA's blog:

-Part 1: Collision Detection

-Part 2: Tree Traversal

-Part 3: Tree Construction

By first constructing a BVH for our mesh, we can considerably reduce the time required to perform these queries:

So, this has given us a 2000x speedup over the naive implementation (this is more a statement of how inefficient the naive version is)! This means we can get the accuracy benefits of using the actual collision mesh geometry, without sacrificing performance.

A reference implementation of this bounding volume hierarchy is available here.

Prediction Benefits

These plots compare actual ball trajectories recorded in Rocket League (solid lines) to the predicted trajectories computed with this model of ball bounce physics, given only the initial conditions (dashed lines). These plots are generated from data file "episode_000121.csv" in the dataset provided here.

Ball locations, as a function of time step:

Ball velocities, as a function of time step:

Ball angular velocities, as a function of time step:

Here, we see that by using actual geometry, we are able to resolve not only the simple bounces with the ground (timesteps 0 to 400), but we can also predict how the ball will roll up one of the cylindrical sides of the wall (timesteps 400-600). The predicted motion closely follows the observed results, even for this long 10-second simulation.