fix: Circles Not Colliding Accurately Fixed

This commit is contained in:
Syntriax 2024-01-27 15:07:07 +03:00
parent 32e2a6e7d3
commit bd43d39367
1 changed files with 13 additions and 13 deletions

View File

@ -66,19 +66,6 @@ public class CollisionDetector : ICollisionDetector
{ {
collisionInformation = default; collisionInformation = default;
{
Vector2D shapeToCircleProjectionVector = shapeCollider.Transform.Position.FromTo(circleCollider.CircleWorld.Center).Normalized;
Projection shapeProjection = shapeCollider.ShapeWorld.ToProjection(shapeToCircleProjectionVector);
Projection circleProjection = circleCollider.CircleWorld.ToProjection(shapeToCircleProjectionVector);
if (!shapeProjection.Overlaps(circleProjection, out float depth))
return false;
if (Math.Abs(collisionInformation.Penetration) > Math.Abs(depth))
collisionInformation = new(shapeCollider, circleCollider, shapeToCircleProjectionVector, depth);
}
var vertices = shapeCollider.ShapeWorld.Vertices; var vertices = shapeCollider.ShapeWorld.Vertices;
int count = vertices.Count; int count = vertices.Count;
@ -96,6 +83,19 @@ public class CollisionDetector : ICollisionDetector
collisionInformation = new(shapeCollider, circleCollider, projectionVector, depth); collisionInformation = new(shapeCollider, circleCollider, projectionVector, depth);
} }
{
Vector2D shapeToCircleProjectionVector = shapeCollider.Transform.Position.FromTo(circleCollider.CircleWorld.Center).Normalized;
Projection shapeProjection = shapeCollider.ShapeWorld.ToProjection(shapeToCircleProjectionVector);
Projection circleProjection = circleCollider.CircleWorld.ToProjection(shapeToCircleProjectionVector);
if (!shapeProjection.Overlaps(circleProjection, out float depth))
return false;
if (collisionInformation.Left is null || Math.Abs(collisionInformation.Penetration) > Math.Abs(depth))
collisionInformation = new(shapeCollider, circleCollider, shapeToCircleProjectionVector, depth);
}
return true; return true;
} }