Up for a challenge?

(If you don’t feel like reading, just skim the bold text)

I have a rather interesting question. It is not some simple question about scripting or model importing, it is more or less a “If you were to do this, how would you accomplish it”

I am currently attempting to create a beam of light in unity, one that will be able to reflect off mirrors and split with prisms.

How would you tackle this problem? I am simply looking for advice.

I would really highly appreciate input, I have been stumbling around attempting to locate something that could point me in the right direction.

Thanks, Craze

EDIT: Here is an example of what I am trying to do: http://i699.photobucket.com/albums/vv357/blobthingy/LightExample.jpg

I’d probably use particles for the beam itself, I haven’t played with their settings in a while but there was a way to make it so they basically look like a solid beam after the initial ‘fill’ time. A billboarded plane could work as well, it just depends on how you need the beam to look (solid color, color transition, varying colors simulating different materials, etc.)

I’d do a raycast in the original direction of the beam, set to collide with a specific collision layer that would contain all the mirrors and prisms, and then clone the particle object at the point of impact, facing the new direction(s) as appropriate. Having it stop or pass through terrain and other obstacles depends on your needs obviously.

If the layout doesn’t change in realtime you can pre-position everything, otherwise raycast a few times per second to adjust as needed. Each new beam could be part of a tree structure, so that every time the original (root) node needs to redo the collisions, it recursively destroys all its children. For easy reflections, I’m guessing the Vector3.Reflect(..) method would probably work (though haven’t touched it yet myself).

Alternately, each prism and mirror could have a particle component that can be turned on/off, along with methods that get triggered when a beam hits it, that calculate the direction(s) to reflect or split the beam in. This would save you having to instantiate and destroy objects all the time, you’d just be turning components on and off which is less performance-heavy.

Hope some of this helps, though I’d be happy to hear of any easier or prettier solutions by some of the masters here :slight_smile:

Simple - Fake it with other game objects.

Thanks CSDG

I just thought I’d let you guys know I actually created what I needed.

Here is a picture of it functioning in real time at about 750 frames per second: Pic

It is a mixture of all of your ideas really, I doesn’t use real angles and functions mainly off raycasting.

Thank you all for your time!