x


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?

more ▼

asked Apr 28 '10 at 01:51 AM

jc_lvngstn 1 gravatar image

jc_lvngstn 1
266 8 9 20

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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

more ▼

answered Apr 28 '10 at 02:30 AM

e.bonneville gravatar image

e.bonneville
5.7k 100 116 165

Thanks! I completely forgot about the line renderer. I think part of my brain filed it under "drawing 1 pixel lines". Silly me. I'll check it out, and see if it meets my needs.

Apr 28 '10 at 02:32 AM jc_lvngstn 1

This looks like it will be perfect. I assume in order have a "flowing" effect, you will just swap out textures, each one shifted slightly?

Apr 28 '10 at 02:38 AM jc_lvngstn 1

Yeah, that should do the trick.

Apr 28 '10 at 03:19 AM e.bonneville

Vote up and accept answer?

Apr 28 '10 at 03:19 AM e.bonneville

Thank you, elbon96!

Apr 28 '10 at 12:19 PM jc_lvngstn 1
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Apr 28 '10 at 01:58 PM

3dDude gravatar image

3dDude
2.6k 65 76 103

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x107
x55
x24
x14
x5

asked: Apr 28 '10 at 01:51 AM

Seen: 6262 times

Last Updated: Apr 28 '10 at 02:02 PM