# Steering behaviors: how to flee then go back towards the hunter?

I have implemented a Wander and Flee steering behavior and it works like this:

When the entity is not hunted by anything it wanders around. But when it is hunted by the player it will flee away from the player at growing speed. This is like a butterfly that flees quickly.

But now I want to change its behavior. So that when the entity is hunted by the player, it flees away at the beginning. But if the player keeps chasing the entity it will go back towards the player at a slower speed so that the player can catch the entity. In my previous implementation the player cannot catch the entity because the entity always has a fleeing force if the player comes closer.

Can I just decrease the fleeing force over time? But this still cannot guarantee the entity is catchable and it will make player feel the entity is not moving.

You could start decreasing the fleeing force as soon as it exceeds a set value and then reset it when the distance from the player starts increasing.

pseudo-code

if(fleeingforce greater than X)
beingchased is true
previousdistance from player = length(player.xyz - self.xyz)

if(beingchased is true)
if fleeingforce > minfleeingforce
decrease fleeingforce
if(distance from player is greater than previousdistance)
beingchased is false

• It still looks like the entity stops there waiting for the player. Maybe I decrease it too fast. Commented Aug 29, 2017 at 14:12
• you can put a minimum fleeingforce to the chased entity that still allows the player to catch up to it while not making the fleeingforce become lower than the minimum, see edited answer Commented Aug 29, 2017 at 14:14
• Thanks this works better. But it is really hard to push the entity towards the player. The best I can do is make the entity move slower so that the player can catch the entity. Commented Aug 29, 2017 at 14:47
• If you want the entity to move towards the player just calculate the vector to the player by doing (player.xyz - entity.xyz) and move the entity in the direction of this vector. Commented Aug 29, 2017 at 14:52