- Home /
Reflective laser 2D, unity.
Hi everybody! I was wondering what's the best way to create bouncing laser in unity in 2D mode. Is it:
creating plane, putting texture on it and stretching along RayCast
LineRenderer (there are some bugs about it, for example: width isn't constant when there are many bends/count of vertices)
list of linerenderers (but then how get exact linerenderer from list in case of we wanted destroy or change it somehow)
new method that I don't know?
I have problems with creating easy game a'la Lasers&Mirrors from Android Google PlayStore. I'm tired of it and that's why I'm asking you here. If you could, please, give some pro tips or partial code of how to create such laser. Sorry for noobish approach, I'm totally new in it. Thank you in advance!
Looked for Lasers&$$anonymous$$irror on the play store and couldn't find it.
Is your question more how to visualize that, or what a good algorithm would be?
Oh, it's name is "Lazors" (hope, it's not kind of ad and I won't be punished for that :P ) . I'd rather want to get some piece of advice or tips how to construct both algorithm and visualize it (because I don't know whether I should use linerenderer or something else).
Answer by hexagonius · Feb 12, 2015 at 10:54 AM
What you could do:
raycast from one hit point to the next at the desired angle until you either reach a limit or the outer walls (whatever stops it)
from each hitpoint draw either a 2 vertex linerenderer to the next (helps not getting folded ends), or a generated quad
the quad will give you more precision on the ends (like keeping it parallel to the surface you hit), but that's more work of course
You can also program a particle emitter to generate lines
In addition place cool looking glow points on and aligned to the hit surfaces
Of course you'll need to keep track of hitpoints, renderers etc, but just recalculating everything everytime the laser origin is modified should be enough
How's that?
Particle emitter seems new to me, I'll check it out and let you know if it's enough for me :) Thanks for quick response! But in case I'd like to put some kind of divider, which divides laser beam into 2 separeted beams , it's starting to be more complicated to use linerenderer, isn't it?
Particle emitter is the best option. Thank you very much! Now I have to find out how to make laser appear instantly like in ArcReactor from unity asset store :P