Mass Affector
Mass affectors enable dynamic vehicle physics by contributing mass and position to center of mass calculations. As fuel depletes or cargo loads change, the vehicle's handling characteristics update automatically.
IMassAffector Interface
Components implementing IMassAffector contribute to the vehicle's mass, center of mass, and inertia calculations. The interface requires three methods:
float GetMass()- Current mass in kilogramsVector3 GetWorldCenterOfMass()- World position of this affector's center of massTransform GetTransform()- The affector's transform
MassAffector Component
MassAffector is a simple implementation that contributes a fixed mass at its transform position. Use this for static mass contributions like passengers, cargo, or equipment.
Properties:
mass- Mass contribution in kilograms (default: 100kg)
For dynamic masses like fuel tanks, create a custom IMassAffector that returns varying mass values.
Usage with VariableCenterOfMass
VariableCenterOfMass automatically finds all child IMassAffector components (recursively) and uses them to calculate:
- Combined mass (baseMass + all affector masses)
- Combined center of mass (weighted by mass and position)
- Combined inertia tensor (parallel axis theorem)
Enable useMassAffectors in VariableCenterOfMass to activate this system. The component updates these properties each FixedUpdate when marked dirty.
Important: Base values shown in VariableCenterOfMass inspector do not include affector contributions. Combined values are only visible at runtime.