- Home /
Light detecting + Light lowers variable
Hi there.
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!
Answer by Barachiel · Aug 28, 2015 at 04:48 AM
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.
Thank you, I am going to try to use the raycast together with the collider.
Will that work for the AI? NPC detection system. kinda that.
I don't see why it couldn't work with AI as well. Nothing about the solution I suggested involves the player directly, so it's just a matter of implementing it how you'd like.
Answer by cjdev · Aug 28, 2015 at 02:29 AM
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.
Yeah I think I am going to use a collider and raycast. Thank you very much!
Your answer
![](https://koobas.hobune.stream/wayback/20220612001626im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Use of an AI script, and having it NOT go through walls using a character controller 0 Answers
enemy waypoints and detection scipting 2 Answers
AI detection script problem 0 Answers
Enemy AI, detect player when seen 2 Answers
Resize Array Based on Value 2 Answers