A physics-based car game

By Chinh Luu

Introduction

Inspired by the online game Rocket League, I decided to create a physics-based car game, where all the motions of the car is driven by physics forces. Note that the car does not have any tire, so the only operation that really drives the car forward is boosting (there is no physics for tire/ground interactivity). Some other abilities of the car are: jump, rotate in 3D, and hit objects.
This project involves: implicit Euler integration, tri-linear interpolation, and particle system simulation.

The basis to apply physics

It is impossible to apply physics onto every vertex of the 3D car model. There are too many vertices, so the computational cost would be huge. To reduce the problem size, I only apply physics onto some nodes that can represent the whole 3D car shape. These nodes are chosen to wrap around the car model.
cage image

Physics

Implicit Euler Integration is used to solve for the velocities and positions of the nodes based on the current velocity (momentum) and the applied forces.

Spring

A spring is added to each pair of nodes if the distance if they are horizontally, vertically, or diagonally adjacent. This prevents the deformation of the shape when different forces applied to different nodes.

Boosting

To implement boosting, a force is applied to all nodes with the direction being the vector pointing from the back face of the car to the front face of the car.

boost image

Jumping

To implement jumping, a force is applied to all nodes with the direction being the vector pointing from the bottom face of the car to the top face of the car.

boost image

Rotation

To implement 3D rotation, a force in one direction is applied to a face, and a force with the opposite direction is applied to the opposite face.
Pitch rotation: an upward force is applied to all nodes on the front face, and a downward force is applied to all nodes on the back face.
Yaw rotation: a force pointing to the left is applied to all nodes on the front face, and a force pointing to the right is applied to all nodes on the back face.
Roll rotation: an upward force is applied to all nodes on the left face, and a downward force is applied to all nodes on the right face.

pitch
roll
yaw

Collision

Collision with the ball: compute the penetration factor from the radius of the ball and the radius of the nodes and use that penetration factor to compute the collision force.
Collision with planes:


pitch
roll

Render

All of the physics described above is applied to the nodes representing the car model, meaning we are only transforming the nodes, not the car. So how do we transform the car model with respect to the transformation of the nodes? The answer is tri-linear interpolation. At the initialization step, we compute the positions of the car vertices with respect to the nodes. That is then used to compute the positions of the car vertices based on the positions of the nodes while in simulation.

trilinear interpolation Trilinear interpolation from Wikipedia

Particle system for boosting

For boosting, I implemented a particle system to act like the "smoke" the car leaves when boosting. To make this look better, I used a math function to have the color of the particles change accordingly to its angle with respect to the center of the back face. When the car is rolling, the effect looks very satisfying.

Particle system

Some other features

Some other trivial features that I implemented:

Controls

Demo

Libraries/packages used

Special thanks to Dr.Sueda for helping and giving me feedback throughout the duration of the project.