How can I check if my Player leaves a Sphere?

Hello there. I am currently working on my first unity-project (3D). So far i have a working CharacterController and an Enemie which is Patroling if the Player is outside of a given sphere around the enemie. If the Player enters the Sphere, the enemie starts chasing the player until he leaves the sphere again. All that works perfectly fine, but i dont like that the enemie starts patroling right away after the player leaves the sphere. I want it to stand still for a moment (and later animate to look around). To achieve that, i have to chech if and when the player leaves the sphere. I obviously already have a bool which checks if the player is inside the sphere or outside, but i have no idea how to check when the bool turns from true to false again.

Im looking forward for a few helpfull answers

best regards, Sakul156

Thanks in Advance! :slight_smile:

You should look at OnTriggerExit and OnTriggerEnter, from there you can set your bool

You just need a flag. Let it be bool isChasingPlayer for Enemy chasing Player.

If (Player is inside the sphere and isChasingPlayer is false) 
{ isChasingPlayer becomes true;
  Enemy stops all coroutines;
  and starts the chasing coroutine }

If (Player is outside the sphere and isChasingPlayer is true) 
{ isChasingPlayer becomes false;
  Enemy stops all coroutines;
  and starts looking around coroutine }

When looking around coroutine ends, Enemy restarts the patrolling coroutine.

hay, thanks for the fast answer. I started watching a video about those triggers and he said that i need to have a rigidbody. The problem is that i dont use a rigidbody in the project.