Follower stuck doing nothing if blocked by an enemy.

Issue #10294 open
gewd created an issue

Often times a follower will be stuck trying to path to an enemy when it is blocked by another enemy in front of it. I have to manually order the follower to attack the enemy in front.

The AI should check if there is no path detected but there is an adjacent enemy, it should attack that instead of pathing or waiting.

This makes playing with followers really painful.

Comments (8)

  1. gewd reporter

    Another instance with the gnu in front. The boar was attacking the gnu before I saved, it doesn't attack anymore after I loaded the save.

    Gnu engagement style is aggressive.

    Yeah looking at who they are fighting, they are targeting monsters not right next to them or even out of vision and doing nothing even if another monster is attacking them. Enemies can also get stuck this way.

    I think this should be enough examples. Let me know if you need more. It constantly happens when there are narrow passages like this.

    As I mentioned, the AI should prioritize attacking what is in front of them if their pathway is blocked by a hostile NPC. Or if you made it so it just targets the closest hostile if it gets stuck, that will be easier than trying to figure out which square is blocking the way to the original target. That is also something that should be fixed, the followers will randomly target some far off monster instead of a closer one.

  2. gewd reporter

    I believe I’ve pinpointed the issue. The problem is that IsHostileTowards, FindPath, and FindTargetOfOpportunity don’t take into account if the monster is hostile to the leader, it only takes into account if the NPC is hostile to the target. You also cannot use PartyLeader.IsHostileTowards if the party leader is the player because that always seems to return false. I have a small workaround here that you can put in XRL.World.AI.GoalHandlers.Kill.TakeAction(). Insert it right after “if (findPath.Usable)”. This doesn’t fix all cases though. you will want to fix the root cause in those methods I mentioned and perhaps check every level of PartyLeader, not just the first level. But this should be a good proof of concept that proves there is an issue and it can be fixed.

                            GameObject enemyInFront = currentCell3.GetLocalCellFromDirection(findPath.Directions[0]).GetCombatTarget(base.ParentObject);
                            if (enemyInFront != null)
                            {
                                bool hostileToTarget = this.ParentBrain.IsHostileTowards(enemyInFront);
                                bool hostileToLeader = false;
                                if (this.ParentBrain.PartyLeader != null)
                                {
                                    hostileToLeader = enemyInFront.IsHostileTowards(this.ParentBrain.PartyLeader);
                                }
                                MessageQueue.AddPlayerMessage(string.Format("leader {2} hostile {0} - {1}", hostileToTarget, hostileToLeader, this.ParentBrain.PartyLeader), null, true);
                                if (hostileToTarget || hostileToLeader)
                                {
                                    MessageQueue.AddPlayerMessage("switching to enemy in front", null, true);
                                    this.Target = enemyInFront;
                                    this.PushChildGoal(new Kill(enemyInFront));
                                    return;
                                }
                            }
    

  3. Log in to comment