fix: Shape Collision on Larger Shapes

This commit is contained in:
Syntriax 2024-01-26 19:13:53 +03:00
parent 6a84c3ec1a
commit 85bad951ff
1 changed files with 16 additions and 1 deletions

View File

@ -5,6 +5,7 @@ public record Projection(float Min, float Max)
public static bool Overlaps(Projection left, Projection right) => Overlaps(left, right, out var _);
public static bool Overlaps(Projection left, Projection right, out float depth)
{
// TODO Try to improve this
bool rightMinInLeft = right.Min > left.Min && right.Min < left.Max;
if (rightMinInLeft)
{
@ -19,7 +20,21 @@ public record Projection(float Min, float Max)
return true;
}
depth = default;
bool leftMinInRight = left.Min > right.Min && left.Min < right.Max;
if (leftMinInRight)
{
depth = right.Max - left.Min;
return true;
}
bool leftMaxInRight = left.Max < right.Max && left.Max > right.Min;
if (leftMaxInRight)
{
depth = right.Min - left.Max;
return true;
}
depth = 0f;
return false;
}
}