# Physics Engine

This page contains various information about the internals of the physics engine, in no particular order.

## Start Boost

The start boost charge is a floating-point variable. Its initial value is zero. Then, on each of the 240 frames before the race starts, the game updates it based on controller input. If the acceleration button is pressed, the new charge value is `lastCharge + (0.02 - (0.02 - 0.002) * lastCharge)`

. Otherwise it is `0.96 * lastCharge`

. The new value is then clamped between 0 and 1.

When the race starts, the charge is used to index into an array to get the number of frames of the start boost.

Minimum Charge | Maximum Charge | Boost Duration |
---|---|---|

0 | 0.85 | 0 |

0.85 | 0.88 | 10 |

0.88 | 0.905 | 20 |

0.905 | 0.925 | 30 |

0.925 | 0.94 | 45 |

0.94 | 0.95 | 70 |

0.95 | 1.0 | 0 (Burnout) |

## Wheel Physics

Wheels move along a fixed axis with respect to the vehicle position, and propagate collisions with the floor to the body of the vehicle.

Each frame, the following algorithm is applied.

- The wheel transformation matrix is computed. For the back wheel, it is simply a rotation by the current player orientation followed by a translation to the current player position. For the front wheel, it is preceded by the handle translation/rotation matrix that's based on the values from bikePartsDispParam.bin.
- The wheel topmost position is computed by multiplying the position from the BSP by the transformation matrix.
- The bottom direction vector in the wheel reference frame is computed by multiplying the unit bottom vector by the reduced transformation matrix (without the translation vector).
- The scalar wheel position along the axis is incremented by 5 in the bottom direction, and capped by the maximum value from the BSP.
- The wheel position is updated by adding the bottom direction vector multiplied by the scalar position to the wheel topmost position.
- The hitbox center position is computed by adding the difference between the wheel radius and the hitbox radius from the BSP to the wheel position, again along the axis.
- The KCL collision algorithm is performed with the hitbox center and radius as arguments.
- If a collision with the ground is found, the wheel position is moved in the direction of the normal to the ground, such that the hitbox becomes tangent to the ground.
- The wheel position is projected back onto the axis.
- The wheel speed along the axis is computed by subtracting the difference between the current position and the topmost position, to the same difference from the previous frame.
- The normal acceleration from the wheel is computed by multiplying the speed and the scalar position by their respective suspension factors, adding them together and projecting them onto the absolute vertical axis.
- The normal acceleration is added to the total vertical acceleration from the player.