AI struggling with moving around other characters

I am using the top-down template, and I’m having some problems with the way the AI is trying to navigate around other characters. Here’s what I’ve tried so far, and it hasn’t worked. I can’t be the first person to have player and enemy characters moving around in the top-down template, so clearly I’m doing something wrong and hopefully someone can help me.

When I press play, and I click to tell the player character to move, it does just find moving around stationary obstacles, such as the blocks in the top-down template. But when I place an enemy character in the world and click to have the player character move to the other side of the enemy, then the player character tries to run through the enemy, fails, and just keeps bumping into the enemy. So, the pathfinding is clearly not taking into account the presence of the enemy character.

To solve this, I have tried checking various combinations of “can ever affect nav” in the enemy’s root, collision capsule, and static mesh component. Some of those have no effect at all. Others will cause the player character to go around the enemy character as we would hope. Sounds like the solution is just to pick the latter, right?

Wrong. The problem is that when I do that, and then I give the enemy character the ability to move around with a behavior tree, the player character does not realize that the enemy character has moved. So, the player character still avoids the enemy character’s original position, but bumps into the enemy character repeatedly at its new position.

Poking around online, I discovered that maybe the solution has to do with having the nav mesh generate dynamically during runtime. Sounds wonderful. So, under project settings, nav mesh, runtime generation, I switched it to dynamic rather than static. But now both the enemy and player characters shake bizarrely when moving around.

I just want the player and enemy characters to be able to move around and not bump into each other all the time. Any suggestions?

You have any luck solving this? I’m struggling with the same issue right now.

i would suggest watching the open world game series by CodeLikeMe on YouTube.

You can tweak this a little bit by changing the width of the capsule. For instance a wider margin helps with crowd control. While I also have the AI issue bumping into the player I did not looked into it yet, but this may be overcome by using Dynamic for the navmesh generation (under project settings). perhaps try this?

Dynamic is already enabled by default as far as I know. Mine is already set dynamic and it doesn’t help. Units which stop moving don’t generate Null areas on the navmesh so other AI units think they can walk through them. Or they attempt to if they think it’s a path to go somewhere. They won’t seek alternative paths. If you have 2 hallways and both went to the same area, and in Hallway A you had an AI unit standing in the middle blocking the way. AI B is closest to Hallway A so it goes down Hallway A thinking it can go to the other room, when it runs into AI A standing in the middle of the hallway, it doesn’t recognize them as an obstacle and just stands there walking into them. It will never realize that the hallway is blocked by the other AI and that it should take the alternate route through Hallway B. RVO and Crowd are only for AIs that are moving with space around them.

You can see this thread for the current issue I’m dealing with: https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/1721770-can-ever-affect-navigation-not-staying-enabled

For others landing on this site like me and don´t know how to fix the problem…
In your character blueprint spawn a invisible plate(static mesh) which can affect navigation. Then when you have set in your project settings the runtime to “Dynamic” your moving characters will always have a little invisible plate between theier feets who can affect the nav map. When they stay in a small corridor the ai will move arround and find another way through it. Cause the way now is blocked by the character(invisible plate object). I recommend using this only for non moving characters (Spawn it when character stops moving, delete it when character start moving). Otherwise it will cost a lot of performance and you will get some new bugs in pathfinding because of the new feature. Hope that helps :slight_smile:

1 Like

thank you this works just fine:)