onMovementBlocked method

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

Implementation

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

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

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

    position += correction;
  }
  velocity -= getVelocityReflection(other, collisionData);
}