Drag

From Trailmakers Wiki
(Redirected from Aerodynamics)
Jump to navigation Jump to search

Drag is a core mechanic of the game which causes blocks to create a force opposing movement. It's also closely related to blocks creating lift/downforce (forces perpendicular to the direction of movement). This mechanic is absent on the Space Sector map while outside of a planet's atmosphere.

Block Data

All blocks in the game have 2 properties which determine the aerodynamics of the vehicle: pass-through and drag coefficients. These properties are determined by the block type and can't be changed.[1]

The pass-through property determines how they are used by the drag calculation. When this property is set, the block can't cover the drag of other blocks. The only blocks with this property set are the small/normal/simple tailfins as well as their powered variants, flat connectors, and all blocks in the Accessories category.

The drag coefficients partially determine the strength of the drag force created by the block. Since the drag calculation only considers the bounding box in build mode of the blocks rather than the actual block model, they determine the individual drag coefficient of each face of the bounding box of each block. All points in the same face of a block always use the same coefficient. All blocks in the Accessories category and flat connectors have a drag coefficient of 0 for all their faces, while all other blocks have a non-0 coefficient.

Calculation

When leaving build mode, the game calculates the effective drag coefficient of each grid point of each face of a block. This coefficient is first initialized to the drag coefficient specified by the block type for the face with the point. After that, the coefficient is set to 0 if the grid space directly in front of the point is filled with a non-pass-through block. The resulting coefficients are never modified after leaving build mode regardless of what happens to the creation, which is the cause of the Zero Drag Glitch.

The result of this calculation can be seen in build mode through the aerodynamics display UI: points with a non-0 coefficient display moving arrows in front of them, with the speed/color of the arrows indicating how big the coefficient is (faster/greener arrows indicate a smaller coefficient).

Outside of build mode, these coefficients are used to determine the drag forces. On each frame, the game takes all the grid points of each block face that points less than 90° away from the direction of movement. For each of these, the game calculates a force vector. This vector always points in the opposite direction of the block's face (i.e., towards the inside of the block), it's positioned on the center of its respective grid point, and its magnitude is proportional to the effective drag coefficient of that point as well as its speed along the axis of the force vector.[2] Additionally, when underwater or very close to it (up to 2-3 blocks above the surface), all points are taken into account, with those pointing more than 90° away from the direction of movement having their drag applied in the opposite direction of what would normally be done (i.e., with the force vector pointing towards the outside of the block).

Mathematically, the result can be expressed through the following formula:

F=cdf(vn)n

Where:

  • F is the resulting force vector
  • cd is the effective drag coefficient for the point
  • f is a strictly increasing, odd function
  • v is the speed vector of the block
  • n is the normal vector of the block face, pointing outwards by convention
  • represents the dot product of 2 vectors

If vn is negative, the resulting force is only considered when underwater.

After all of this is done, each force is applied to its corresponding block.

Notes

  1. Technically the drag coefficient can be changed through the use of mods
  2. This allows the drag force to change when blocks are moved/rotated even though the drag coefficients are constant, which allows things like control surfaces to work.