Physics Engine

From Custom Mario Kart
Revision as of 00:49, 17 December 2020 by Atlas (talk | contribs)
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.

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.