How to trigger an object to move until it's out of sight of the fps controller on sphere collision.

I’m a complete noon at this and have no idea how to start. What I’m trying to achieve is have the player come across another character. Once you (the player) is close enough to that character the character should run away until he’s out of sight and then I need him to disappear. Please help me out! Whatever way you want. I just need those events in that order to happen and only happen when the player will see it. Nowhere on the Internet is a solid answer to this question.

Since you’ve played with sphere colliders but faced the problem when the player leaves the radius of the collider, a simple approach would be to use a sphere or box collider as trigger much bigger than the other collider.

So you’d have two triggers:

  1. The run away trigger, let’s say it’s a sphere collider with radius = 1
  2. The far enough trigger, let’s say it’s a sphere collider with radius = 20

So, when the player enter the run away trigger, the other character runs away until the player is out of the far enough trigger. And then, hide it.

You should setup at least one flag once the character is out of the far enough trigger to disable it and re-enable the run away trigger.

That’s a good Idea! But how would I code that? Linking code to 2 different objects is a little beyond my experience.