From cf23c85834ca440e9c7451925c8084a4bda57455 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 18 Jun 2016 13:07:59 +0100 Subject: [PATCH] Fix Mobile.IsMovingInMyDirection check. self.Location returns mobile.ToCell, so the old code would always return a dot product of 0. --- OpenRA.Mods.Common/Traits/Mobile.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index acaf24036b..27bc9fc80a 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)