- Home /
Light beam for illumination
Hey all! I am trying to create an item similar to the X-Ray visor from Super Metroid. Basically, I am making a 2d game, and I want to use a ray of light emitting from the player that is controllable.
My assumption is that this would be done with raycasting, but I'm struggling with how to rig light to it as well as how to change the direction based on control input. Any help would be amazing!
Note: I am using the free version of Unity, version 4.6.1f1
I've included a still from Super Metroid as a reference for what I am trying to make. I am pretty much trying to duplicate this.
Answer by Sparkels · Aug 13, 2015 at 09:56 AM
use a second camera with script : http://wiki.unity3d.com/index.php?title=IsVisibleFrom to finde if a object is rendered by camera then change shader :
public Shader shader2;
this.GetComponent().material.shader = shader2;
That would give me the X-Ray effect. I'm more just looking for the lighting effect. I know the answer is right in front of me, but I'm driving myself crazy looking for it!
I would also like a more detailed answer to this. I have been stumped and have been trying to code this feature into my game for about a month.
Answer by Glurth · Aug 16, 2015 at 02:59 PM
Since even the black background is getting lit up, the image looks like a mostly transparent, otherwise white (color guess(r,g,b,a)= (1.0,1.0,1.0,0.7) ), triangle is drawn over, and alpha-blended (transparency blending), with everything below it.
One corner of the triangle is fixed to the character's head, and it's orientation is defined by where the character is facing.
I don't think you will need to use real lighting effects and/or raycasting to achieve this effect.
Answer by Ash-Blue · May 03, 2017 at 05:02 PM
You can easily do this with 2 cameras and a depth shader. If you want to create the light dimming effect you'll need a semi-transparent overlay that the depth shader can hit.
See my answer here for step-by-step setup details: http://answers.unity3d.com/questions/1163458/use-an-object-as-a-mask-for-a-camera.html?childToView=1348801#answer-1348801
Your answer
![](https://koobas.hobune.stream/wayback/20220611235621im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
[2D] Find nonobscured corners of 2D sprites or collision boxes? 0 Answers
Torchlight effect in 2D 3 Answers
Physics2D Raycast, check if my raycasthit2D.collider is the same as my gameObject 1 Answer
BoxCast, OverlapArea, and Raycasting; ground detection questions 0 Answers
Directional light 2D 0 Answers