Index: binaries/data/mods/public/simulation/components/UnitAI.js =================================================================== --- binaries/data/mods/public/simulation/components/UnitAI.js +++ binaries/data/mods/public/simulation/components/UnitAI.js @@ -1685,12 +1685,22 @@ "FLEEING": { "enter": function() { - // We use the distance between the entities to account for ranged attacks - this.order.data.distanceToFlee = DistanceBetweenEntities(this.entity, this.order.data.target) + (+this.template.FleeDistance); - let cmpUnitMotion = Engine.QueryInterface(this.entity, IID_UnitMotion); - // Use unit motion directly to ignore the visibility check. TODO: change this if we add LOS to fauna. - if (this.CheckTargetRangeExplicit(this.order.data.target, this.order.data.distanceToFlee, -1) || - !cmpUnitMotion || !cmpUnitMotion.MoveToTargetRange(this.order.data.target, this.order.data.distanceToFlee, -1)) + let cmpPosition = Engine.QueryInterface(this.order.data.target, IID_Position); + if (!cmpPosition) + { + this.FinishOrder(); + return true; + } + + this.order.data = { + "x": cmpPosition.GetPosition().x, + "z": cmpPosition.GetPosition().z, + // We use the distance between the entities to account for ranged attacks + "min": DistanceBetweenEntities(this.entity, this.order.data.target) + (+this.template.FleeDistance) + }; + + // Move away from the attacker's position and not the attacker to avoid fleeing infinitely. + if (this.CheckRange(this.order.data) || !this.MoveTo(this.order.data)) { this.FinishOrder(); return true; @@ -1714,7 +1724,7 @@ "MovementUpdate": function() { // When we've run far enough, stop fleeing - if (this.CheckTargetRangeExplicit(this.order.data.target, this.order.data.distanceToFlee, -1)) + if (this.CheckRange(this.order.data)) this.FinishOrder(); }, @@ -1984,18 +1994,10 @@ this.SetAnimationVariant("combat"); this.SelectAnimation("move"); - var cmpUnitAI = Engine.QueryInterface(this.order.data.target, IID_UnitAI); - if (cmpUnitAI && cmpUnitAI.IsFleeing()) - { - // Run after a fleeing target - this.SetSpeedMultiplier(this.GetRunMultiplier()); - } this.StartTimer(1000, 1000); }, "leave": function() { - this.ResetSpeedMultiplier(); - // Show carried resources when walking. this.SetDefaultAnimationVariant(); this.StopMoving();