#Intelligent AI flee state

1 messages · Page 1 of 1 (latest)

plush prism
#

I have currently implemented a state where an AI flees from another, however when it goes to the game world borders it hugs it on the side, until stopping in the corner. Any ideas for solutions on this would be appreciated.

low quail
#

Do you use pathfinding/navmesh?

#

A simple fix would be to check if the flee position is out of bounds and just find a new random position with brute force.

plush prism
#

The thing is what if this new random position is toward the chasing entity? Seems unrealistic

low quail
#

You can sample a few positions and score them by distance to the player and pick the one with the best score

slender sorrel
#

^ definitely just check a few places and should nothing work that does not require going toward the player, have a cornered state

plush prism
#

Good idea

#

How would you check if your cornered

#

I don’t suppose there’s something navmesh related?

modern quest
lament gulch
#

Cleverly finding the best way to escape from an enemy is a bit tricky!

#

I've done this by randomly sampling points and snapping to the nearest part of the navmesh, then scoring them based on how close they are to a threat

#

But you really want to be able to avoid where the enemy is going, too

#

So you might throw in score based on distance from their expected position

#

this can get expensive

plush prism
#

So here is my idea

#

We have a bunch of points on the navmesh, let’s say we raycast hit a border wall. Now we check for points in an area, for each point we check if the enemy is closer to it then the fleeing npc, if it is then we find another point. Once we find a point we can select that as our new destination. Once we are no longer raycast hitting with a border wall we can return back to our previous state

#

@lament gulch @modern quest @low quail @slender sorrel thoughts?

modern quest
#

Deciding when it stops depends on why the NPC was fleeing in the first place. Is it still being actively chased? Is there a distance threshold? Stamina? Line of Sight? Timer?