fix: Collision Detector CircleCircle Depth Calculation Fixed

This commit is contained in:
Syntriax 2024-01-25 21:53:28 +03:00
parent e7ca96e2e2
commit 3c39e6709d
1 changed files with 5 additions and 5 deletions

View File

@ -50,15 +50,15 @@ public class CollisionDetector : ICollisionDetector
collisionInformation = default;
Vector2D leftToRightCenter = left.CircleWorld.Center.FromTo(right.CircleWorld.Center);
float distanceCircleCenterSquared = leftToRightCenter.MagnitudeSquared;
float radiusSumSquared = left.CircleWorld.RadiusSquared + right.CircleWorld.RadiusSquared;
float distanceCircleCenter = leftToRightCenter.Magnitude;
float radiusSum = left.CircleWorld.Radius + right.CircleWorld.Radius;
float circleSurfaceDistanceSquared = distanceCircleCenterSquared - radiusSumSquared;
float circleSurfaceDistance = distanceCircleCenter - radiusSum;
bool collision = circleSurfaceDistanceSquared <= 0f;
bool collision = circleSurfaceDistance <= 0f;
if (collision)
collisionInformation = new(left, right, leftToRightCenter.Normalized, Math.Sqrt(circleSurfaceDistanceSquared));
collisionInformation = new(left, right, leftToRightCenter.Normalized, -circleSurfaceDistance);
return collision;
}