Hi, all.
Please, I know how to make nav agent chase player and flee from player but, I would want to make it chase player, catch and then, run away from the player until the player cathes him again and it revolves like that.
I would be so honored if anyone helps me out.
I’ve searched in different places but haven’t found any answer to this question.
Your pretty much there dude. Just add something like this…
public enum AiStates {
Chasing,
Running,
}
Character(){
public AiStates aiState;
Update()
{
switch(aiState)
{
case : AiStates.Chasing;
// Do chasing
if (vector3.distance(this, target) <= catchDistance){
// Has caught
aiState = AiStates.Running;
}
break;
case : AiStates.Running;
//Do Runngin away
break;
}
}
}
I have used the switch in case you want to add other states, like catchCooldown, patrol etc.
1 Like