updateSuspension method

void updateSuspension(
  1. num? deltaTime
)

Implementation

void updateSuspension(num? deltaTime){
  final chassisBody = this.chassisBody;
  final chassisMass = chassisBody.mass;
  final wheelInfos = this.wheelInfos;
  final numWheels = wheelInfos.length;

  for (int wIt = 0; wIt < numWheels; wIt++) {
    final wheel = wheelInfos[wIt];

    if (wheel.isInContact) {
      double force;

      // Spring
      final suspLength = wheel.suspensionRestLength;
      final currentLength = wheel.suspensionLength;
      final lengthDiff = suspLength - currentLength;

      force = wheel.suspensionStiffness * lengthDiff * wheel.clippedInvContactDotSuspension;

      // Damper
      final projectedRelVel = wheel.suspensionRelativeVelocity;
      double suspDamping;
      if (projectedRelVel < 0) {
        suspDamping = wheel.dampingCompression;
      } else {
        suspDamping = wheel.dampingRelaxation;
      }
      force -= suspDamping * projectedRelVel;

      wheel.suspensionForce = force * chassisMass;
      if (wheel.suspensionForce < 0) {
        wheel.suspensionForce = 0;
      }
    } else {
      wheel.suspensionForce = 0;
    }
  }
}