NPC Awareness Range In Unity

As you might expect, the easiest way to make an NPC aware of its surroundings is to attach a trigger volume to it. In Unity, this is done by creating a 3d object as a child of your NPC, turning off its renderable and setting its collision type to trigger. Once you add a Rigidbody component to that, the collision trigger can catch an OnTriggerEnter event, which passes in the collider of whatever object it encountered. You can then filter this by any tag or other property in order to let your NPC notice only specific things, such as other NPCs or players.

If a player enters our awareness bubble, do something

That’s really all there is to awareness. Of course, you can approach this differently, such as modelling line of sight using ray casting or increasing the complexity by factoring in ways for players to avoid detection or letting NPCs share what they are aware of between each other. This is enough to get started with, however, and from here you can easily build up your mechanics into pretty much whatever you need.

Game developer with over 12 years of experience, mainly focused on MMOs.