Physics Engine

From Custom Mario Kart
Revision as of 17:44, 24 January 2021 by Stebler (talk | contribs) (Add start boost section)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Under Construction
This article is not finished. Help improve it by adding accurate information or correcting grammar and spelling.

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.

  1. 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.
  2. The wheel topmost position is computed by multiplying the position from the BSP by the transformation matrix.
  3. 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).
  4. The scalar wheel position along the axis is incremented by 5 in the bottom direction, and capped by the maximum value from the BSP.
  5. The wheel position is updated by adding the bottom direction vector multiplied by the scalar position to the wheel topmost position.
  6. 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.
  7. The KCL collision algorithm is performed with the hitbox center and radius as arguments.
  8. 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.
  9. The wheel position is projected back onto the axis.
  10. 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.
  11. 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.
  12. The normal acceleration is added to the total vertical acceleration from the player.