diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index 8d5ab04408..fadca41136 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -179,18 +179,17 @@ namespace OpenRA.Mods.Common.Traits static bool IsMovingInMyDirection(Actor self, Actor other) { - var selfMobile = self.TraitOrDefault(); - if (selfMobile == null) - return false; - var otherMobile = other.TraitOrDefault(); 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(); + 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)