Fix Mobile.IsMovingInMyDirection check.

self.Location returns mobile.ToCell, so the old
code would always return a dot product of 0.
This commit is contained in:
Paul Chote
2016-06-18 13:07:59 +01:00
parent e70590fd94
commit cf23c85834

View File

@@ -179,18 +179,17 @@ namespace OpenRA.Mods.Common.Traits
static bool IsMovingInMyDirection(Actor self, Actor other)
{
var selfMobile = self.TraitOrDefault<Mobile>();
if (selfMobile == null)
return false;
var otherMobile = other.TraitOrDefault<Mobile>();
if (otherMobile == null || !otherMobile.IsMoving)
return false;
// Sign of dot-product indicates (roughly) if vectors are facing in same or opposite directions:
var dp = CVec.Dot(selfMobile.ToCell - self.Location, otherMobile.ToCell - other.Location);
var selfMobile = self.TraitOrDefault<Mobile>();
if (selfMobile == null)
return false;
return dp > 0;
// Moving in the same direction if the facing delta is between +/- 90 degrees
var delta = Util.NormalizeFacing(otherMobile.Facing - selfMobile.Facing);
return delta < 64 || delta > 192;
}
public int TileSetMovementHash(TileSet tileSet)