2D Top Down FlashLight RayCast Help.
Hi guys, im new here and iam trying to make a flashlight cone in a top down 2D game, but I want it to stop in the walls. I read that RayCast can help me but i did not find any tutorials, how can i use RayCast in the flashlight ? Thank You.
Answer by Zeoli · Feb 24, 2016 at 04:36 PM
Hi @bruninDx,
Is there a reason you don't want to use an actual spotlight? as that would solve all your issues. See image.
If you want to use a fake light then I'd give this tutorial a spin, it is very easy to follow and you get to learn a fair amount about RayCasting. https://www.youtube.com/watch?v=rQG9aUWarwE
Thank You for the tutorial, the problem that i have with the actual spotlight is because the light dont stop in the 2Dcolliders, i dont know if i'm doing something wrong or it dont work with 2D stuff .
Thank You.
@bruninDx Unity treats every game as 3D, even the 2D ones. So lighting would be like shining a light at the side of a bit of paper. You could make your objects 3D and use an orthographic camera ins$$anonymous$$d, this will render lighting properly but give you the 2D effect.