onBlockedMovement method

void onBlockedMovement(
  1. PositionComponent other,
  2. CollisionData collisionData
)

Implementation

void onBlockedMovement(
  PositionComponent other,
  CollisionData collisionData,
) {
  _lastCollisionData = collisionData;

  if (_bodyType.isDynamic) {
    Vector2 correction;
    double depth = collisionData.depth.abs();
    if (depth > 0) {
      depth += 0.08;
    }

    correction = (-collisionData.normal * depth);
    if ((other is BlockMovementCollision) && other._bodyType.isDynamic) {
      correction = (-collisionData.normal * depth / 2);
    }

    correctPositionFromCollision(position + correction);
  }

  velocity -= getVelocityReflection(other, collisionData);
}