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;
|
collisionInformation = default;
|
||||||
|
|
||||||
Vector2D leftToRightCenter = left.CircleWorld.Center.FromTo(right.CircleWorld.Center);
|
Vector2D leftToRightCenter = left.CircleWorld.Center.FromTo(right.CircleWorld.Center);
|
||||||
float distanceCircleCenterSquared = leftToRightCenter.MagnitudeSquared;
|
float distanceCircleCenter = leftToRightCenter.Magnitude;
|
||||||
float radiusSumSquared = left.CircleWorld.RadiusSquared + right.CircleWorld.RadiusSquared;
|
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)
|
if (collision)
|
||||||
collisionInformation = new(left, right, leftToRightCenter.Normalized, Math.Sqrt(circleSurfaceDistanceSquared));
|
collisionInformation = new(left, right, leftToRightCenter.Normalized, -circleSurfaceDistance);
|
||||||
|
|
||||||
return collision;
|
return collision;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue