Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Source/Hitbox/HitboxRender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void OnGUI()

private void DrawHitbox(Camera camera, Collider2D collider2D, HitboxType hitboxType, float lineWidth)
{
if (collider2D == null || !collider2D.isActiveAndEnabled)
if (collider2D == null || !collider2D.isActiveAndEnabled || ShouldCullCollider(camera, collider2D))
{
return;
}
Expand Down Expand Up @@ -186,5 +186,17 @@ private void DrawHitbox(Camera camera, Collider2D collider2D, HitboxType hitboxT

GUI.depth = origDepth;
}

private bool ShouldCullCollider(Camera camera, Collider2D collider2D)
{
Bounds bounds = collider2D.bounds;

Vector3 min = camera.WorldToViewportPoint(bounds.min);
Vector3 max = camera.WorldToViewportPoint(bounds.max);

bool overlap = (min.x < 1 && max.x > 0 && min.y < 1 && max.y > 0);

return !overlap;
}
}
}
}