AI to run away from player

Hello all,

I know how to set AI (cube) to follow the player (another cube), but I can’t figure out how to reverse it, the AI to run away from player.

why is everyone asking the same question the last week?

take a look here:

1 Like

I think u know about navmesh, so if you use navmesh, there are various options like seek and flee in the steering actuator, so create a navmesh, select the red cube and and add an always sensor and connect it to the steering actuator changed to flee, and select the object, I hope this will help

1 Like

parent your AI to your player. Your player will never ever be able to reach the AI. Basic question → basic answer.

this is easy, instead of chasing the player, switch it over to chase something else in you level.

Have it track the opposite direction from the player for a second and then have it run zig-zag or whatever you want

Here’s a working demo:

Stalk/Flee Demo

1 Like

is it possible without a navmesh ? Like in space ?

Yes, this is called a way-point system. Basically marked points in 3D space that tell the A.I where they are. Or they can also tell the A.I to go to a particular marker, such as if you are defending or attacking a certain objective area such as a player base. Note: You can setup markers with simple empty objects.

I’ve made that for my game. On a circular checkpoint node setup, if the ennemy tries to escape you by maximizing the distance between you and him, the best way for him to go around you all the time trying to avoid you, is just to find a way to go to you… but not on the shortest path, but the longest.

Thus, it’s easy. Just use any algo to find the shortest path and for each M distance separating 2 connected nodes A,B, use instead a very huge number minus M . 1000000 - distance(A,B)

Cases :
Panic stance - If shortest path is a segment of the longest path, your npc is trapped. But this wont occur on a circular setup since the npc doesnt want to put himself in a no-go area ; the algo above will ensure he will never get trapped since he’s on a path that leads to you (the longest)
Idle stance - shortest path distance is roughly the same than the longest path distance : he cannot add more distance between you and him.

Ofc, the algo has to exe often since the 2 characters are constantly moving, hence the shortest/longest path computed are constantly updated.

1 Like