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:
@@ -179,18 +179,17 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
static bool IsMovingInMyDirection(Actor self, Actor other)
|
static bool IsMovingInMyDirection(Actor self, Actor other)
|
||||||
{
|
{
|
||||||
var selfMobile = self.TraitOrDefault<Mobile>();
|
|
||||||
if (selfMobile == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
var otherMobile = other.TraitOrDefault<Mobile>();
|
var otherMobile = other.TraitOrDefault<Mobile>();
|
||||||
if (otherMobile == null || !otherMobile.IsMoving)
|
if (otherMobile == null || !otherMobile.IsMoving)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Sign of dot-product indicates (roughly) if vectors are facing in same or opposite directions:
|
var selfMobile = self.TraitOrDefault<Mobile>();
|
||||||
var dp = CVec.Dot(selfMobile.ToCell - self.Location, otherMobile.ToCell - other.Location);
|
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)
|
public int TileSetMovementHash(TileSet tileSet)
|
||||||
|
|||||||
Reference in New Issue
Block a user