[SOLVED] How to detect if an object/character is being shined on with a spotlight

Hello, I’m trying to make a game, that includes a player having a flashlight that uses Spotlight.
If the Spotlight shines on something, for a example, a player’s torso, I want it to print out what it detects (like the player’s torso). I’ve been trying to find something that works for ~2h now and I can’t find anything that works now.
Any help is very appreciated :smiley:

1 Like

I’m not entirely sure what the best method for this is, but I would maybe take a look at shape casting! You could have some kind of cone shapecast (possible with the updated version) coming out of the flashlight while it is on that is constantly checking for a players torso (or whatever else you wish to check for). This does require some knowledge of raycasting, but this is just how I would approach the problem.

I personally found this video very helpful for shape casting, by Crusherfire: https://youtu.be/EIOwGMZYidw?si=LteyHIOlHr2TT0I2

Thanks! I’ll check it out now and see if I’m gonna be able to implement this into the game. I do have to check how raycast works since I’ve only used it once. Also thanks for putting a link to a tutorial on raycast!

You can either use raycasting, or look at devforum for a “Light detection module”, if you’re in a dark ambient and there isn’t any other source of light.

Try shapecasting, you could raycast the cone, and if it hits a descendant of the characters model, you can findfirstchild and get the torso.

I’ve already checked the Light Detection Module, sadly it didn’t work. Would’ve made things easier lol

It works! tysm :]
I did have to change some things, like how the shapecast didnt work until the flashlight was put back into the inventory so I did had to use

local RunService = game:GetService("RunService")

while RunService.Heartbeat:Wait() do
   --code
end

instead. Still, thank you so much for telling me about Shapecasting! I never heard about it so it helped a lot.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.