What's the best way to draw beams?

Making projectile weapon is pretty simple. But how do I draw beams, lightnings, other things with variable length?

For linear things scaling might work. If you need to draw trails that follows a path there are a few options, for instance:

  • Modify a model with a vertex shader.
  • Use particles. For advanced effects you could draw the particles to a separate buffer and do post fx with it.
1 Like

I found a solution based on gameobject-manipulation for my fixed-length lasers.
To make that work for variable length i would try the following:

  • To prevent distortion while scaling you first need your laser texture to be of one pixel width.
  • You then create a collection with one sub-gameobject containing your laser-sprite on position [0,0,0]
  • You can then control the x-axis scaling of the sub-object to the desired length by script.
  • Because objects are scaled in both directions, your script needs to substract the half of the length from the x-position, so your laser always starts in the center and expands to the negative x-axis. Here it is important that you subtract from the sub-object containing the laser-sprite, and not the whole collection object.
  • This way when you rotate the whole collection, your laser-sprite should always look forward and have the desired length

Though i did not test this by myself yet, the above solution may have flaws. But i guess it’s worth a try :slight_smile:

2 Likes