NavMesh flee. Ai flee from player. (562184)

This script makes ai fallow player :

    var player: Transform;

function Start(){

    player = GameObject.FindWithTag("Player").transform;

}
function Update() {
 

    GetComponent(NavMeshAgent).destination = player.position;

}

Now,how can i make AI RUN AWAY From Player. Just Run away from player with navmesh. I know i have to get player vector and then i have to make an Ai to move there. Or maybe there is an other option?
Help me out smart people!

Pick a point where you want the AI to run to and make that the NavMesh target - you choose the hueristic to decide where the run away point is…

e.g. 10*player.transform.forward

No,i dont need a specific point,i need ai to run away from player without points,it is possible if player vector is found and then somehow make ai run to that player vector point,so there is no specific NavMesh targets,like waypoints or anything…
Thanks for reply anyway :slight_smile:

Yes, you do need a specific point. You need to feed the agent a target position.

Just subtract the enemy.position from the player.position to get a direction and multiply the normal of that and add the enemy.position to get a point away from the player/

1 Like

You can select a random point away from the player and/or change the target frequently.

also - you could disable navmesh and programmatically move every tick in a direction away from player

1 Like

If you wanted you could use a modified Dijkstra algorithm to find the optimal path away from the player. You could build this to take into account distance, cover, terrain and so forth.

1 Like