AudioAsset
Ease
FastString
FontAsset
NineSlice
PackedSprite
PackedSpriteID
RB
   HardwareSettings
   IRetroBlitGame
RBAsset
Rect2i
ShaderAsset
SoundReference
SpriteGrid
SpriteSheetAsset
TMXMapAsset
   TMXLayer
   TMXLayerLoadState
   TMXObject
   TMXObjectGroup
   TMXProperties
Vector2i

Rect2i.IntersectionDepth

Method

public Vector2 IntersectionDepth(Rect2i rect)

Parameters

rect Rect2i Other rect

Returns

Vector2

Intersection depth

Description

Calculates how far another rectangle intersects into this rectangle. The returned depth represents how much the rectangle would have to be offset so that it no longer collides. This method is useful in collision resolution.

Example

void Update() {
    // Check for intersection, and resolve.
    if (playerRect.Intersects(blockRect)) {
        var depth = playerRect.IntersectionDepth(blockRect);
        playerRect.x += (int)depth.x;
        playerRect.y += (int)depth.y;
    }
}

See Also

Rect2i.Intersect
Rect2i.Intersects
Rect2i.Contains