Merge pull request #11470 from pchote/fix-direction-check

Fix Mobile.IsMovingInMyDirection check.
This commit is contained in:
Oliver Brakmann
2016-06-22 22:49:03 +02:00
committed by GitHub

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)