Creating Lazer Eyes

Yes, I know I spelled ‘laser’ wrong. But that’s just how I spell lazer because Z is a cool futuristic letter and lazers are also cool and futuristic. Anyway… I’m going to outline a couple techniques I used to produce this lazer vision effect in Jettomero using Unity3D’s line renderer component.
lazerdemo
Ignoring the fact that each eye has it’s own beam, let’s focus on a single beam. The beam is made up of 3 line renderers. One is a solid line – the other two use a jagged lightning-like texture which I animate from script.
supersimplelightning
When using the Unity line renderer it’s a good idea to store your Vector3[] for the line points in it’s own separate array since the line renderer annoyingly doesn’t have a property or function to retrieve them otherwise. So all 3 line renderers in the beam should use the same start and end points – that much should be obvious. Now, we’ll want to get the 2 points of the beam to find the distance between them. Why? So we can adjust the tiling on the lightning material so that it doesn’t get stretched out when the beam becomes shorter or longer. Take a look at my Update function on a script I attach to the lightning lines.

    void Update () 
    {
        currentOffset -= Vector2.right * Time.deltaTime * scrollSpeed;
        float length = Vector3.Distance(positions[0], positions[1]);
        GetComponent<LineRenderer>().material.mainTextureScale = new Vector2(length/5.0f, 1);
        GetComponent<LineRenderer>().material.mainTextureOffset = currentOffset;
    }

You can see I calculate the length of the line each frame and then apply that to the mainTextureScale of the line renderer material (the length/5.0f is just an arbitrary value for how many tiles I want per unit of distance). That keeps the lightning arcs consistent across any length.

The other thing I do in the update function is animate the texture offset. I store a Vector2 on the script which can be continually changed over time using a speed that I randomize within a range in my start function. If you’re using multiple lines for an animated effect you will want to randomize the speed and start offset so that they aren’t all running overtop one another and you’ll get a much nicer effect. Here’s my start function:

    void Start () 
    {
        randomOffset = Random.Range(0.0f, 1.0f);
        Vector2 currentOffset = new Vector2(randomOffset, 0.0f);
        scrollSpeed = Random.Range(4.0f, 6.0f);
    }

Finally, for the end of the lazer I have two particle systems – one dispersing some sparks from a sphere emitter. The spark lines are just a thin cross texture all being spawned at a single point using random rotation, random start size, and a size over lifetime from 0 to 1. It’s the same effect I use for the sun’s rays in Jettomero only much faster.

screen-shot-2016-09-29-at-10-47-38-am

If there’s anything here that isn’t totally clear please let me know and I’ll try to elaborate more thoroughly. This technique isn’t too fancy but it is a very simple way to get an interesting effect.