updateWheel method

void updateWheel(
  1. Body chassis
)

Implementation

void updateWheel(Body chassis) {
  final raycastResult = this.raycastResult;

  if (isInContact) {
    final project = raycastResult.hitNormalWorld.dot(raycastResult.directionWorld!);
    raycastResult.hitPointWorld.vsub(chassis.position, _relpos);
    chassis.getVelocityAtWorldPoint(_relpos, chassisVelocityAtContactPoint);
    final projVel = raycastResult.hitNormalWorld.dot(chassisVelocityAtContactPoint);
    if (project >= -0.1) {
      suspensionRelativeVelocity = 0.0;
      clippedInvContactDotSuspension = 1.0 / 0.1;
    } else {
      final inv = -1 / project;
      suspensionRelativeVelocity = projVel * inv;
      clippedInvContactDotSuspension = inv;
    }
  } else {
    // Not in contact : position wheel in a nice (rest length) position
    raycastResult.suspensionLength = suspensionRestLength;
    suspensionRelativeVelocity = 0.0;
    raycastResult.directionWorld!.scale(-1, raycastResult.hitNormalWorld);
    clippedInvContactDotSuspension = 1.0;
  }
}