From 1d88b96361757ac9646c75eec3e35b9fef587dfe Mon Sep 17 00:00:00 2001 From: Olvior Date: Wed, 13 May 2026 13:39:37 +0200 Subject: [PATCH] Added culling for hitboxes outside the screen --- Source/Hitbox/HitboxRender.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Source/Hitbox/HitboxRender.cs b/Source/Hitbox/HitboxRender.cs index 6c6d0d0..2ee0066 100644 --- a/Source/Hitbox/HitboxRender.cs +++ b/Source/Hitbox/HitboxRender.cs @@ -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; } @@ -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; + } } -} \ No newline at end of file +}