Fix CreateEffectWarhead's HitShape distance check

Originally, this was comparing distance beween pos and unit.CenterPosition with HitShape's OuterRadius. However, the OuterRadius can exceed the shape for Capsule and Rectangular shapes, so I tried to adress that a few months ago by using the DistanceFromEdge check instead. The approach was bogus, though. DistanceFromEdge just calculates the distance of a position to the edge, so by comparing it with the distance between pos and victim.CenterPosition in combination with using LengthSquared, it was entirely possible the explosion would be within the HitShape, but closer to the edge than the victim.CenterPosition and the check would return false.
Now we just check if DistanceFromEdge is 0 or negative, which means the impact is inside the HitShape.
This commit is contained in:
reaperrr
2016-04-26 18:01:19 +02:00
parent 3a8a8110be
commit fe7fe9b49b

View File

@@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Warheads
continue;
// If the impact position is within any actor's HitShape, we have a direct hit
if ((unit.CenterPosition - pos).LengthSquared <= healthInfo.Shape.DistanceFromEdge(pos, unit).LengthSquared)
if (healthInfo.Shape.DistanceFromEdge(pos, unit).Length <= 0)
return true;
}