Hi everyone,
I’m developing a pathfollowing component for tanks in my game.
I integrated it with the crowd detour logic in the engine.
I use GetMoveFocus for every frame in the FollowPathSegment of my component to obtain the location to move towards.
This works okay for avoiding other agents that are also moving.
However, I have a hard time configuring my agents to avoid stationary tanks.
To try and resolve this I make use of a NavModifierComponent which is set to filter null, aka not navigable when the agent is not issued any movement orders. And has its navigation relevancy set to false when the agent needs to move.
This works great for when the agent is not close to stationary agents, however, when
the agent does get close the MoveFocus of the crowd controller seems to get very confused
basically, the focus flips between frames back and forth between two or three locations:
- a sensible move focus which would allow the agent to avoid things.
- in front of the agent.
- sometimes the focus will jump to a location opposite of 1. this does not happen if there are no modifiers used!
If we take a look at how the movefocus is determined in CrowdFolllowingComponent.cpp, we find the following:
So the focus gets set to nearly zero sometimes causing it to take the position in front of the agent.
This is fine if there is some consistency to it, however, in the case of using navmodifiers the changes are so radical that the agent is not able to move at all at times…
Is this an engine bug?
Any advice is greatly appreciated!
I also tried to:
- set the nav filter to default instead of relevancy to false
- set the nav filter to obstacle instead of null to attempt to persuade agents to go around.
→ both also lead to the same problem
EDIT:
I think i found part of the problem, In RecastNavMesh.cpp at the InvalidateAffectedPaths function I find that almost every single frame the recast navmesh invalidates any path that goes through the tiles that are affected by the modifier I placed on my stationary tanks.
This causes a recalculation of the path in the path following component which results in the jittering of the move focus of the crowd controller.
This also explains why I don’t have any issues driving (far) away from stationary tanks as in that case the path does not get invalidated by recast as those paths are not subject to the modifiers?