applyLinearImpulse method

void applyLinearImpulse (Vector2 impulse, Vector2 point, bool wake)

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.

@param impulse the world impulse vector, usually in N-seconds or kg-m/s. @param point the world position of the point of application. @param wake also wake up the body

Implementation

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

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

  _linearVelocity.x += impulse.x * _invMass;
  _linearVelocity.y += impulse.y * _invMass;

  _angularVelocity += _invI *
      ((point.x - _sweep.c.x) * impulse.y -
          (point.y - _sweep.c.y) * impulse.x);
}