fix: Collision Detector CircleCircle Depth Calculation Fixed
This commit is contained in:
parent
e7ca96e2e2
commit
3c39e6709d
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue