I am working in a team for making a game, and there is this problem we have.
We want to have monsters that detect light, when they do detect light they will investigate it.
They will be like curious, but the idea is that if they would be exposed to the light, they will slowly die. (there skin would come off and such.)
We thought of a cone collider (for like a flashlight) but we wouldn’t know what to do if the player is like inside a house. (collider would collide through the walls…)
Also there would be lamps, spotlights ect, which would all need a collider.
So questions are:
How do you make AI detect light?
(Guess with a line of sight?)
How do you let the AI die, when exposed to light?
Thanks a lot!
Since there’s no practical way of getting the lighting data from the shader itself I would actually use colliders like you suggested. To make sure they don’t trigger on other obstacles place them in their own layer with the enemies so they only interact with each other. Then you can use the distance of the enemy collision from the light sources to sum up the total light on the enemy.
I imagine the easiest way, if not the most efficient, would be to have a collider in the shape you want, set it to be a trigger and, in your code, check whatever enters it for an appropriate tag to determine if it’s a monster.
To be able to tell if there are walls in between, you could cast a ray from the source of the light to the monster, checking if anything is between the two. There’s a lot more to it for a decent set up, but that’s the basic direction I’d start in.