- Home /
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
Answer by TheCraze · May 24, 2011 at 12:52 PM
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!
Looks nice. Are you actually reflecting the beams or just rotating them 90 degrees?
Answer by TheDemiurge · May 22, 2011 at 08:08 AM
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 :)
I would really like to be able to change it in real time, because it really has no use otherwise(besides graphical additions).
Hmm, I appreciate the thought you have put into it, I am going to go play with some raycasting(though I am not very experienced with it).
Yeah, I had to play around with raycasting too. Be sure to use the versions that take advantage of RaycastHit, since that has all the relevant information. And you'd probably want the bit about the Layer$$anonymous$$asks as well, depending on the kinds of objects you need to 'pass through'.
Well, having just started with the ray casting, I am measuring distances between mirrors and making sure they are actually hitting the mirrors.. :p
I have made some progress on having the objects aware of rays hitting them, checking the direction it comes from and outputting another ray, but it is still very buggy.. :/
Answer by UniteMage · May 22, 2011 at 06:03 AM
Simple - Fake it with other game objects.
Thanks CSDG
So you would have the game object continually extend until it hits another game object?
If it hits another game object it would calculate the angle from there? Would it then create a mesh going off into another direction?
Imagine the texture issues and how the gameobject would react when it has nothing to hit.
I have found one of the more logical ways to approach it is actually to use a particle trail, but I am not quite sure how to make the object react to the angles at such a high speed that it appears to leave a trail resembling a beam of light and not a slow moving object with a trail.
I can't give you a specific answer as this is far away from my expertise, but I believe what you want to be accomplished would require blob projectors, as the beam can easily be made with spotlights, but the reflection would require shader coding.
Logically, the light only has to appear real.. it doesn't require shaders to actually reflect it.
I was assu$$anonymous$$g their must be some way to do this with Rays, but I just am stumped on how to make it behave realistically.
I appreciate the thought though Bravini :)!
Your answer
Follow this Question
Related Questions
Full reflection mirror 0 Answers
Ray Light Effect 2 Answers
My raycast is not always in the forward direction. 1 Answer
Reflect ray of light using mirrors? 2 Answers
How is this effect done? 1 Answer