Search Unity

Bouncing Lightning

Discussion in 'Visual Effect Graph' started by bjedlowski97, Feb 4, 2020.

  1. bjedlowski97

    bjedlowski97

    Joined:
    Feb 13, 2018
    Posts:
    46
    I want to create a bouncing lighting vfx, I was able to create lightning, but for this game I am working on it is wanted to bouncing between enemies. It is possible in the graph to make something like that happen or will i have to leave it to the coders on the project?
     
  2. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi @bjedlowski97 ! To confirm, you want lightning (electricity) to bounce between enemies, like chain-lightning?

    If so, then yes, but you'll still need to tell the graph where the enemies positions are. If you don't want to leave it to the coders, you can use the VFX Binders, specifically the Multiple Position Binder. Add an exposed Texture2D and an exposed int property to blackboard, then add a VFX Multiple Position Binder component to your VFX game object and link the properties and the targets.

    After this, depending on the type of effect, you can use a Sample Texture2D node or a Set Position from Map block to read the positions of the enemies (they are stored as 1x1 pixel color values in the texture, so if you have 4 enemies, the texture will be 1 pixel high and 4 pixels wide and reading the 3rd pixel will give you the world position of the 3rd enemy).

    Below is the basic setup.

    Of course if you want to dynamically change how many enemies are there, which one should be hit first, etc. then a bit of code to populate the Multiple Position Binder would be necessary.

    Hope this helps!

     

    Attached Files:

  3. bjedlowski97

    bjedlowski97

    Joined:
    Feb 13, 2018
    Posts:
    46
    Thank you for the help, I have tried to set it up as you showed here, I believe I did everything properly. I set the binder and set it to some objects in the scene, but I am unsure how I should properly use the set position from the map block to get it to jump between the objects. So far from what I have it is aware fo each enemy position but when I change the index number the particles don't seem to follow it to make a chaining effect, instead, they just spawn in the positions not moving to the new position as I want. I attached an image of the effect I would like to achieve with this if that helps.
     

    Attached Files:

  4. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi, you need to store the current and the next position and then blend between them. This example works for 2 enemies (just to create a straight line of particles traveling between them, even when they move), but hopefully it'll be enough to get you started :)

    Just note that the two position blocks in Update are in World position (the little W icon) since that's the space we get the enemy positions in.
    upload_2020-2-21_18-19-29.png
     
    mancuso likes this.
  5. deXter_47

    deXter_47

    Joined:
    Jun 21, 2020
    Posts:
    2
    Apologies to dig up this old thread. I tried the method with particle strips as output particles but particles are not even spawning. Can you please have a look what I am doing wrong.
     

    Attached Files: