- Home /
Check if an object has a light shining on it
I'm developing AI for my game, and I want to test if the object my AI is attached to has a light being shined on it, and I'm not sure the easiest way to go about this. My ambient light is completely black, and I have a few lights throughout my game(Point lights and spotlights)
Is there a way to actually detect this without access to the render texture to sample pixels?
Answer by testure · Jun 23, 2011 at 04:21 AM
If you're looking for a simple solution, you could just put a trigger on your light that has a large enough radius to encompass the amount of light that's being output, and when the character enters the trigger just raycast to them and see if line-of-sight exists. If so, then boom- your character has light shining on it. It's not a pixel-perfect solution, but it could do the job just fine, and it'd be extremely efficient.
for the spotlights- you'd probably want an extra step in there before the raycast. you could check the dot product of the light's position vs. the character's position to see what the angle is, that way you don't get false positives when the character is behind a spotlight.