- Home /
 
How to make a laser beam effect with raycast?
Hey everyone, new here but I'm looking to make a raycast laser beam effect similar to something like in portal, where the laser hits an object and makes object reacts in some way (that parts not important). What I really can't figure out is how to make a physical laser beam effect. I found this tutorial online which provided the code:
 #pragma strict
 
 var LaserOrigin: Transform; // Put the laser (line renderer) object here.
 
 var LaserTarget: Transform; //The point light object.
 function Update () {
 
         var ray =  new Ray(LaserOrigin.transform.position, LaserOrigin.transform.forward); //Casts a new ray
 
         var hit: RaycastHit;
 
       
 
         if(Physics.Raycast(ray, hit, Mathf.Infinity))
 
         {
 
          
 
                 LaserTarget.transform.position = hit.point; //Positions the light at the same point the laser hits something.
 
         }
 
       
 }
 
               I created the line renderer with a perlin noise material, and put it as the public variable, but when I use this script, the light beam doesn't show up, or when I turn the Use World Space off, it only goes like 1 unit out. What is the best way to create a laser beam effect? If possible, I was hoping to use a particle system as well. Thank you for your help in advance.
Answer by KwahuNashoba · Apr 09, 2015 at 07:58 PM
Look at this tutorial: https://youtu.be/l86gpYbQFzY?t=13m32s
I think that it's what you need :)
Your answer