Is there any way to detect if part is lit up?

I am trying to make a vampire-esque enemy, when light is shone on the enemy it disappears, when there is no light it appears.

However, I’m not sure if there is any way to do this without premade regions where every light is.

I’ve created bricks that are under lamps that the NPC can detect and change transparency, however this doesn’t really work as it’s too sudden. I suppose I could loop it but I’d rather see if there is a built in function first.

2 Likes

@Maximum_ADHD made an open source test around 4 years ago that allows you to determine when a certain position is “illuminated” by a SpotLight.

Obviously it isn’t the most updated method given it was made 4 years ago and there could be better ways of doing so, but it’s the best I remember on a system like this being done. I haven’t seen any recent methods of doing this nor do I know how to do it myself.

https://www.roblox.com/games/228940223/Cone-of-Light

Not sure if something like this is what you’re looking for though. Give it a shot.

Edit: Not recommended, as replied below:

@FragmentFour I would recommend that you do a “OnTouched” function for a part above the light its a much simpler solve and you can use it to change the transparency or brightness of a light. Hope this helped.

I would advise against using this because its method of querying lights is very inefficient.

2 Likes

You can use a combination of tags, via the collection service using the tag editor plugin, and magnitude. First you can tags all the parts that have a light with a special “Light” tag and then use the collection service to get all the parts with the “Light” tag and then check the magnitude in respect to the vampire’s root part position. This will only work as expected if the direction in which the light is pointing does not matter.

2 Likes