applyForce method

void applyForce(
  1. Vector3 force, [
  2. Vector3? relativePoint
])

Apply force to a point of the body. This could for example be a point on the Body surface. Applying force this way will add to Body.force and Body.torque. @param force The amount of force to add. @param relativePoint A point relative to the center of mass to apply the force on.

Implementation

void applyForce(Vector3 force, [Vector3? relativePoint]) {
  relativePoint ??= Vector3.zero();
  // Needed?
  if (type != BodyTypes.dynamic) {
    return;
  }

  if (sleepState == BodySleepStates.sleeping) {
    wakeUp();
  }

  // Compute produced rotational force
  final rotForce = _bodyApplyRotateForce;
  relativePoint.cross2(force, rotForce);

  // Add linear force
  this.force.add2(force, this.force);

  // Add rotational force
  torque.add2(rotForce, torque);
}