Advice on how to make AI NPC perceive how dark an area is
Hi guys!
Quick question, I am not looking for anyone to lay it out step by step how to do this but more like point me the right direction.
I am working on a part of a level that requires the player to sneak and how dark parts of the level are does need to play a role in whether enemy AI characters detect them or not. I have google and youtube searched this a ton and found nothing useful. Can someone point me in the right direction on what to look for?
We are talking specifically about AI perceiving how dark a specific part of a level is and having it influence whether or not they can see the player character.
Possibly you could have a blueprint that has volume and a darkness variable. Whenever the AI overlapped with the volume it would change his AI Sight seeing cone or something. So on the AI Overlap event you would cast to see if its the correct volume blueprint and be able to get the nessary variable off of it.
You could also do this for only really dark areas where the begin overlap sets the AI Sight to barley nothing and then the end overlap sets it back to a regular value.
These volumes would be in various places in your level.
Just one idea that wouldn’t be to performance heavy
What moves and is visible or not is the player.
As such, all of those calculations have to happen on the player, for the player.
Then the AI can be made to just access and read the final values when the player is in sight/spotted.
Common ways of “detecting visibility” are running a line trace from a single point towards all light sources and getting/polling the results.
You can set up a system, and then run it for every bone in the skeletal mesh. Or maybe define which bones to run it from in an array list or similar.
You can use various methods of polling the results. But it’s generally boolean on an per-check basis.
Obviously the system also needs to access and check the light parameters in use, since a spot light can trace as visible in a line trace while the player is outside of its cone radius.
Calculations to that extent become increasingly complex. I mean. Maybe? Not really?
A cone is just a linearly increasing set of circles.
You calculate from the light forward in its forward vector, and compute the radius for the distance at which the original point was to check if it is outside or inside that radius. It’s not quite that easy. But it doesn’t have to melt a GPU either…