Feature #2229: Improve pathfinding AI
Posted: 01 Jun 2015, 07:11
I've submitted a PR for fixing the "running in circles" thats seen is AiCombat. https://github.com/OpenMW/openmw/pull/602
I'm providing this post because I believe the fix requires a bit more explanation than just the PR.
I believe the problem is the pathing can have problems when it "overshoots" a nav point.
Basically, at t = 0, NPC is pointed at a nav point, and is close but not within the "reached navPoint" threshold.
time advances by one frame, and NPC position is updated.
At which point NPC is now gone past the nav point, and is past the threshold again.
So AI starts turning the NPC around, while still running at full speed.
And because NPC can only turn so fast, well, you get the "running in circles" effect.
Simplest fix would be to increase the navPoint threshold. Changing the value from 32 to 80 will do it.
But this makes the pathing sloppy. So fix only applies the higher threshold when it looks like a navPoint has been overshot.
Easist way to test that I've found is go to Dreen Plantation
Turn on God Mode and togglepathGrid.
Set speed to 300.
Then walk up to "Frinnius Posuceius" and punch him.
Frinnius and "Hrargal the Crow" should start chasing you.
If you run around the huts they tend to start "running in circles" around at the navPoints at corners.
Note, I haven't applied fix to other AI packages at this stage.
I've also looked into #2559 some more. https://bugs.openmw.org/issues/2556
On further investigation, the "spin at the corner" is not due to pathfinding.
Instead, it appears to be due to the script ColonyUryn attached to "uryn maren".
The script directs uryn to the destintation in a series of AiTravel commands.
The spin occurs when the end point of the on AiTravel segment is off the ideal path.
So, if uryn is not moving after he finishes the first AiTravel segment, it suggests a problem with the script.
As sjek and I are unable to reproduce, I'm going to suggest this be closed, as I believe it's a problem with one of the plug-ins Alex C had loaded.
I'm providing this post because I believe the fix requires a bit more explanation than just the PR.
I believe the problem is the pathing can have problems when it "overshoots" a nav point.
Basically, at t = 0, NPC is pointed at a nav point, and is close but not within the "reached navPoint" threshold.
time advances by one frame, and NPC position is updated.
At which point NPC is now gone past the nav point, and is past the threshold again.
So AI starts turning the NPC around, while still running at full speed.
And because NPC can only turn so fast, well, you get the "running in circles" effect.
Simplest fix would be to increase the navPoint threshold. Changing the value from 32 to 80 will do it.
But this makes the pathing sloppy. So fix only applies the higher threshold when it looks like a navPoint has been overshot.
Easist way to test that I've found is go to Dreen Plantation
Turn on God Mode and togglepathGrid.
Set speed to 300.
Then walk up to "Frinnius Posuceius" and punch him.
Frinnius and "Hrargal the Crow" should start chasing you.
If you run around the huts they tend to start "running in circles" around at the navPoints at corners.
Note, I haven't applied fix to other AI packages at this stage.
I've also looked into #2559 some more. https://bugs.openmw.org/issues/2556
On further investigation, the "spin at the corner" is not due to pathfinding.
Instead, it appears to be due to the script ColonyUryn attached to "uryn maren".
The script directs uryn to the destintation in a series of AiTravel commands.
The spin occurs when the end point of the on AiTravel segment is off the ideal path.
So, if uryn is not moving after he finishes the first AiTravel segment, it suggests a problem with the script.
As sjek and I are unable to reproduce, I'm going to suggest this be closed, as I believe it's a problem with one of the plug-ins Alex C had loaded.