Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Pulsing Lights using Particle Systems

Discussion in 'Editor & General Support' started by DanielBarnes, Nov 5, 2020.

  1. DanielBarnes

    DanielBarnes

    Joined:
    Nov 4, 2020
    Posts:
    4
    Hi all,

    I'm hoping someone might be able to point me in the right direction. Basically I'm trying to create a Tron-esqe environment and want to have small pulses of light move along grid lines.

    My thought had been to use particle effects to emit glowing spheres along the grid lines, but that's proven more difficult than I thought it would. I also realized it probably won't work well with curved geometry, although I did see somewhere someone wrote a script to do just that.

    My other thought had been to create a sprite object(or whatever to emit a glow) and manually animate it. This is basically going to be used for a cutscene environment so I only really need it to look right in the camera frame.

    The cube is a test asset I put together with a standard unity cube and a simple grid texture. For actual objects, I will be mapping the UV maps to the material to as texture.

    I just want to be able to have a small pulse of matching light barely thicker than the lines move along the line for a short distance, or even static spots that glow and dim softly. Something to break up the uniformity and give it a little extra detail.

    Thanks!
    (Sorry if this isnt in the right place.)
    example geometry.jpg
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
    You could place a small piece of geometry like a teardrop and move it along the line, give it a brighter color. That coupled with some post processing for the glow might do the trick. For dimming in and out, you could drive the color up and down.
     
  3. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    I know this might not be the most convenient answer, but I'd most likely attempt this via a shader. You could fairly easily create a shader that gets brighter in certain spots, and allow those spots to move. That's particularly easy if you want the bright spots to move across a regular surface, like a cube. That would also most likely be a very performant approach.
     
    Kurt-Dekker likes this.
  4. DanielBarnes

    DanielBarnes

    Joined:
    Nov 4, 2020
    Posts:
    4
    Digging through the asset store I found a volumetric line package that someone was kind enough to put together. The effect is more or less what I was looking to create. I still like the idea of using a shader. Messing with the metallic and smoothness sliders on the ground plane material I could get an interesting effect if the camera is facing the right direction(if I even can animate material attributes like that).

    Animation is a harsh mistress I've never seen eye to eye with.

    Right now all the laser are prefabs with simple animations. Originally they were all firing in unison because they all had the same animation clip. I couldn't figure out how to offset them on a prefab by prefab basis, so I made different animation clips and applied them to different prefabs with different offsets. I know there has to be a better way to do it. It just feels criminally inefficient.

    Logically, a script should be able to set speed and offset time, although i'm not sure how to go about making it affect individual prefabs and not all of them. I've not dug too deep into the animation tools in the scripting API yet.

    I also attempted to animate the attributes on the script nodes controlling the lines, to see if I could control the visiblity by phasing it down to zero and back. I can see the values changing, but there's no change in the environment, either in the scene or game view. I assume it has something to do with the way the script generates the lines, or I need to add an Update() method to tell it to redraw them as values change.

    Or I could do battle with the particle system. I know it can do the same thing, its just a matter of figuring out what controls what.

    I really appreciate any thoughts.


    gif_animation_002.gif
     
    Kurt-Dekker likes this.
  5. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,120
    I don't know exactly what controls the spawn time or speed of any given prefab, but I would think it should be pretty easy to write a simple script you can add to that prefab to help randomize the behavior a bit. For example, if you're using an actual Animator on your prefab, you could create a script that simple calls
    this.gameObject.GetComponent<Animator>().speed = UnityEngine.Random.Range(0.7f, 1.3f);
    in its Start(), to make all animations on that instance randomly run a little faster or slower. If the speed is controlled by some other means, it should still be a similar process for giving it some randomness.

    Other than that, I'm not sure if there's anything else you're asking for feedback on. If you're using a lot of these I'd recommend making sure you're reusing them, rather than creating and destroying them as that get too far away. Maybe you don't need to worry about that if it's just a few.
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,756
  7. DanielBarnes

    DanielBarnes

    Joined:
    Nov 4, 2020
    Posts:
    4
    yup, that's the asset I found. Saved me a huge amount of time trying to figure out how to make the Line Renderer behave like that. Figured it'd be best to see what people had already put together before trying to reinvent the wheel.

    Rather than trying to figure out how to pause the animation cycle I decided to make life easy on myself and just make a pause animation where the laser sits invisible at the starting spot point. Then I could update the play/pause with different random values. I also made an alternate prefab with exposed values to control speed/pause in case I wanted to make something synchronized.

    I still want to animate the values on the line controller script. I realized I could do it with animation events, but those don't interpolate over time, and there's no curves to adjust on them apparently.


    auto 004.gif
     
    Kurt-Dekker likes this.