applyLinearImpulse method

void applyLinearImpulse(
  1. Vector2 impulse, {
  2. Vector2? point,
  3. bool wake = true,
})

Apply an impulse at a point. This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. This wakes up the body if 'wake' is set to true. If the body is sleeping and 'wake' is false, then there is no effect.

impulse is the world impulse vector, usually in N-seconds or kg-m/s. point is the world position of the point of application (default: center of mass) wake decides whether to wake up the body if it is sleeping (default: true)

Implementation

void applyLinearImpulse(Vector2 impulse, {Vector2? point, bool wake = true}) {
  if (_bodyType != BodyType.dynamic) {
    return;
  }
  point ??= worldCenter;

  if (!isAwake) {
    if (wake) {
      setAwake(true);
    } else {
      return;
    }
  }

  linearVelocity += impulse * _inverseMass;
  _angularVelocity += inverseInertia *
      ((point.x - sweep.c.x) * impulse.y - (point.y - sweep.c.y) * impulse.x);
}