How to draw beams?

Such as homeworld, etc. The "Beam" is likely a simple quad stretched between two points, where the Z axis is always rotated to face the camera. (fyi I'm not certain the particle system would work in this case, as it's not as straightforward to generate an exact beam between two points, and I haven't had much luck generating a solid beam of particles. I might look into this a little more, though)

The challenges as I seem them are:

  1. The texture will be stretched the longer the beam. I would likely want to tile the texture instead. A solid beam wouldn't matter, but a beam with energy waves would need to be tiled.

  2. It seems like the beam's Z Axis would be rotated to face the camera, so you always see the full flat beam, not a flat poly if you are a low angle.

The way I think I would go about this is:

  1. Find the distance between the beam emitter and the target.
  2. Create a quad of that length, and the width of the beam.Not sure just yet how to tile the texture depending on the length of the beam/quad.
  3. Find the y rotation difference between the two points, and rotate the beam that amount.
  4. Do the same for the x axis.
  5. The Z rotation would depend on the location of the camera in relation to the Z axis...if that makes any sense. In my head...it almost seems like the beam's Z rotation will always be perpindicular to camera view angle.

Anyone have any suggestions on going about this?

I've got one simple solution - use Unity's built in Line Renderer, the docs for which are found here.

the way i do it is i use raycasts first create a empty GameObject then make a cylinder scale its z axis to .5 then rotate is 90 degrees on the x then make it a child of the empty gameObject set the x position and the z position to 0 then make the z to .5 so that the empty gameObject is at the very back of the empty gameObject. the code attached to the empty gameObject should be:

function Update () { var hit : RaycastHit;

if(Physics.Raycast(transform.position,transform.TransformDirection(Vector3.forward),hit)){
    var distance = Vector3.Distance(transform.position,hit.point);

    transform.localScale.z = distance;

}
else{transform.localScale.z = 5000;}

}

So i don't know how to make it have a texture but you can use a plane or somthing that will work with a texture. but make the y 1 not 0.5.