- Home /
Bouncing Laser Beam
What I am trying to achieve is a segment of a laser beam that would bounce between two players in a pong style game.
The raycast-line renderer combination I have implemented from here creates a continuous line not a laser beam segment.
Does anyone know how I may achieve this segmented ray?
Actually LineRenderer creates lines between points you define, so to make a 'beam' (with 'pew' sound, I hope? xD) you have to update line start and line end points of your beam each frame.
So yes, I know how you could achieve this, but I will not do coding ins$$anonymous$$d of you. :3 Though you can ask for advices and tips. ;)
Answer by CunningGrayFox · Jul 04, 2015 at 01:22 AM
I'm going to post my own answer in the hopes that future readers can use this as a very simple solution to an issue that is highly over complicated by most developers. But first...
@incorrect: Your comment wasn't helpful and rather insulting. I'm a web dev for a Fortune 500, I can write my own C#/.NET code. I posted this question in an attempt to avoid not only reinventing the wheel but also to see if someone had a simpler solution for what seems to be a common usage of a laser beam in games. If, as a developer, you always have tunnel vision and focus on one thing you'll never see the possibilities of a better, cleaner, and more elegant solution. If, as a developer, you never pull from the collective wisdom of your peers you'll never have as much knowledge as they have collectively. Finally, your snide comment is useless because the simplest solution requires zero coding effort.
TL;DR Put a trail renderer on the "ball" that gets ping ponged around; remove its sprite and then just tweak the trail renderer to achieve the desired affect. Et Voila!
If you want a non-physics based solution you'll have to write a bit of code to get the Raycast, LineRenderer, and Reflection to work just right.
I've been attempting to do the same thing, and have used the trail renderer. However I'm having issues making it look right, as it seems the trail renderer does not show immediately at the time when you instantiate your "ball", or whatever it is attached to.
For instance, if 'X' were the instantiation point and "|" is a collider on my player object, the trail starts showing a little late.
|X [gap here] ==========O
I need this:
|X===========O
Any thoughts? I can't move my instantiation point back, because I don't want my "ball" to collide with "|"