How does it work?
Very simple!!
1.First u chose Server or local script
2.Require the Module Script
3.Call the function CheckLight from the model
to call it u need Basepart and boolValue
The Basepart is the part that u want to check if its in light
The boolValue is true or false and it FIlters a model if the base part is in one (if true it wont count it as invisible) – NOT REQUIRED
He is probably doing a trick I learned from working with gpu coding. Basically we can represent “brightness” in a sense by treating it as a vector, where say we have a direction of our light and the brightness is the length of that vector. We can then compare the angles of those vectors (1 being the source of lights vector and the other being the “normal” of the face Graphing Calculator) and then from there seeing if the angle is some value, say 180 degrees (pitch black)
It’s really simple man all you are doing is just checking their angle difference. Watch I know its swift code but it really gives a good explanation (this is where I learned it from)
Do you mean like just comparing its dot product to the other? Like in a sense transposing its “range” to the radian range of the dot product of them and seeing if its less than?
Looks like this uses Cameras instead of rays. Unorthodox, but it works.
One critique is that there could be a memory leak if you call the CheckLight function on too many objects. You might consider having a single Heartbeat function that goes through a queue. Also, you probably don’t need to make a new SunPart for every object that you’re checking.
Well first at all I get all the lights in workspace and put them in a tabel after that
I put a camera in the part that I want to check if it’s in light. Then I roll through the tabel with the lights and check the magnitude between them. If the light range is bigger than the magnitude then it check if there are parts on the way of the light to the part.For that I use camera and get the obstacles in the camera direction
. If there aren’t any then I return it true for point light only. For the other 2 lights I do the same thing but j also check the angle of the part and the light if its in this angle I return true. For the sun I make position which follows the sun and I detect if there is something in the way of the camera again. If the lights are set to cast shadow only then they just check the magnitude and the angle for the surface light and the other one (forgot the name).
Neat! I have a question for the third gif.
Is it possible to make something for the character to have, and when he has it, the light doesn’t detect him?
This is a super clever use of Camera:GetPartsObscuringTarget!
Very neat!
For anyone wanting an explanation, what this basically does is orient a camera at the source of each light, and then it checks if there is anything blocking that light from the target object. You could achieve the same effect with regular ray casts as these are what are used internally by GetPartsObscuringTarget afaik, but, this is a super clever way to go about it.
A simplified explanation is to think about what you see (what a camera sees). You are pretty much seeing any beams of light that enter your eyes, or enter the camera. So, if you do the opposite, and imagine your camera is the light source (imagine the beams of light travelling backwards), you can decide what things can “see” the camera (which is acting as the light source).