onVelocityUpdate method

  1. @override
Vector2 onVelocityUpdate(
  1. double dt,
  2. Vector2 velocity
)
override

Implementation

@override
Vector2 onVelocityUpdate(double dt, Vector2 velocity) {
  if (!handleForcesEnabled) {
    return super.onVelocityUpdate(dt, velocity);
  }
  final oldVelocity = velocity.clone();
  List<Force2D> mergeForces = [..._forces, ...gameRef.globalForces];
  final acceleration = mergeForces.whereType<AccelerationForce2D>();
  final resistence = mergeForces.whereType<ResistanceForce2D>();
  final linear = mergeForces.whereType<LinearForce2D>();

  Vector2 newVel = onApplyAccelerationForces(acceleration, velocity, dt);
  newVel = onApplyLinearForces(linear, newVel, dt);
  newVel = onApplyResistenceForces(resistence, newVel, dt);

  return (oldVelocity + newVel) * 0.5;
}