Forum Thread
Poll: Is raycasting a good way to give NPC eyesight? (2 votes)
  Posts  
How to give NPCs eyesight (Forums : Coding & Scripting : How to give NPCs eyesight) Post Reply
Thread Options
Jan 9 2019 Anchor

I am currently creating an advanced npc system with c# in Unity. I am experimenting with giving the npcs eyesight so they can evaluate their surroundings. Currently the most effective method I have used is raycasting. I am concerned about how this would effect performance on a larger scale. Just a few npcs in the scene all shooting anywhere from 1 to 30 raycasts a second is ok but what about 50 npcs or even 100. Does anyone have any suggestions for how to give npcs eyesight. I will be posting some code snippets and gifs soon.

2018 09 12 9

Description of photo above:

The npcs is shooting 3 raycasts a second (blue rays) towards the player, if it hits the player then that indicates the player can see the npc. When the npc (small red person center of image) realizes it is in view of the player (green capsual) it shoots the yellow rays and then shoots a raycast from the player to the location the yellow ray hit. If the ray shot from the player hits a location within a close range to the yellow ray then that indicates the player will be able to see the npc if it tries to take cover there so the ray appears red, otherwise it shoots a green ray at the locations that are not within a close range to indicate better cover locations.

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.