Search Unity

World-space system inheriting velocity of game object?

Discussion in 'Visual Effect Graph' started by dgoyette, Jun 1, 2020.

  1. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    I'm making a moving object that should leave particles behind it as it moves. I've set the system to World, which causes it to leave the particles behind, but I haven't found a way for them to inherit the velocity of the VFX graph which is moving. Ideally it would inherit the velocity, but some drag would slow it down. I tried adding a block to inherit source velocity, but this doesn't seem to do anything.

    I'm starting with a default "Swarm Particle System", and I have a simple script to move the VFX Graph game object. Can anyone suggest an approach to having particles inherit the velocity of the system at the moment they're initialized?
     
  2. JulienF_Unity

    JulienF_Unity

    Unity Technologies

    Joined:
    Dec 17, 2015
    Posts:
    326
    Hi, at the moment you have to do it manually by exposing a property to pass the velocity to the graph (typically the gradient of the position of the object)
     
    dgoyette likes this.
  3. kayronjm

    kayronjm

    Joined:
    Jun 15, 2019
    Posts:
    34
    I'm having a similar problem with this and that doesn't seem to work either.

    upload_2020-6-14_0-43-45.png

    I'm just trying to get the particles shot out to use the weapon turret's current velocity (this exposed Vector3 is set by C# code prior to triggering the start event) and then add the random velocity locally.
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    The approach that JulienF mentioned worked fine for me. I similarly have a Vector3 property on the VFX graph, which I use just like you use, except that for mine it's set to world velocity, not local velocity as you have it:

    upload_2020-6-13_21-11-27.png

    Then I just the velocity in code:

    Code (CSharp):
    1. vfxSystem.SetVector3(VisualEffectConstants.PreRift.SystemVelocityParameter, Velocity);
    2. vfxSystem.Play();
    3.  
    Seems to work fine for me. Make sure you're not having issues with Local vs World.
     
  5. kayronjm

    kayronjm

    Joined:
    Jun 15, 2019
    Posts:
    34
    Thanks for that! I tried setting velocity in World as well as Local but neither seem to work OK. Perhaps it's the velocity vector I'm setting that's the issue. I had set it to the velocity vector of the weapon turret carrying the VFX graph in it so it made sense to me. Maybe it's also the fact that I'm adding a random local velocity to it. I don't know really.
     
  6. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    If you're adding more velocity, that should be fine. But if you're ever "setting" the velocity, that will step over this, so you shouldn't be setting the velocity more than once.
     
  7. kayronjm

    kayronjm

    Joined:
    Jun 15, 2019
    Posts:
    34
    Thanks, yeah, I understand that. I managed to get it working as expected. The particles were dragging behind too much for my liking but it was my fault - I had Drag values set too high. :p Turns out for my use-case, it looks better to just keep everything local anyway, but at least with this thread, I've learned how to sort this out for other use-cases. Thank you.
     
  8. Delacroz

    Delacroz

    Joined:
    Sep 23, 2019
    Posts:
    13
    Hey, can you please tell me how you did to leave particles behind it as it moves? thanks!
     
  9. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    It's subtle, but within the nodes of the graph you'll see a small button you can toggle between World and Local. Usually you just need to make sure the rendering is done in World, to prevent the particles from moving along with the moving system.
     
  10. Delacroz

    Delacroz

    Joined:
    Sep 23, 2019
    Posts:
    13
    thanks!
     
  11. Ofenkatze

    Ofenkatze

    Joined:
    Aug 14, 2013
    Posts:
    15
    Hey everyone!
    Sorry for necro, but it's 2023 now and I wonder if anything has happened on this front? Couldn't find a node for inherit emitter velocity, but since documentation is still spotty, I thought I'd ask.
     
  12. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    194
    Morning Sir.
    If you want to easily retrieve the Velocity of your VFX Graph object what you can do is :

    • Create a Vector3 Property and make sure to turn the "Exposed" value on.
    • Name it to something meaning full like "System Velocity" or else.
    • Use this property where you want to use it. (ex: use it to set the initial Velocity)
      upload_2023-7-24_10-4-10.png

    • Drag your VFX Graph in your Scene and select it.
    • In your Inspector Tab, add a "VFX Property Binder" component to your VFX Graph.
      This Component Script will allow you to easily "Bind" your exposed velocity property to your VFX Graph Velocity.
      upload_2023-7-24_10-9-28.png
    • Click on the "+" sign to create a new Binding and go in the "Transform" category to select "Velocity"
      upload_2023-7-24_10-12-59.png
    • Once this is done, Select the Velocity Binding and set the Property to your exposed Property (in my case, I've named it "System Velocity"). And set the Target by assigning your VFX Graph Transform. If everything is properly linked, the Orange Square should change color to Green.
      Unity_CKxuliHEot.gif

      Your VFX Graph Velocity is now properly binded to your Vector3 exposed property. You can use it as you want in your graph. In my example, I'm Inverting the Velocity by multiplying it by -1 so that the particles are pushed behind by VFX Graph direction (like Smoke Exhaust from a car).
      Hope this will help. Have a great day.

      Unity_ST1DkBROwr.gif
     
    ATate likes this.
  13. Ofenkatze

    Ofenkatze

    Joined:
    Aug 14, 2013
    Posts:
    15
    Thanks so much for the detailed answer, Orson!
    I'll try it today and let people here know how it went or if questions arise. Just wanted to say, I love Unity Forums, you people are so helpful and saved my day more than once <3
     
    OrsonFavrel likes this.
  14. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    194
    Thanks a lot for your message and don't hesitate to come back if you need more information.
     
  15. FunkyHippo

    FunkyHippo

    Joined:
    Nov 5, 2016
    Posts:
    1
    Hi there! Reviving this as well...
    I tried to use your approach, Orson, and it works somewhat. I have a weird issue where it seems to only work for some particle emissions. If I have a constant emission rate only some of the particles actually inherit the velocity, and if I instead use a burst only some bursts of particles inherit the velocity. For the burst either all particles of a burst inherit the velocity or none do, which is a bit weird. I've just used a burst in the gif below as it clearly illustrates how some of the burst inherit the velocity while others don't. I've also added an image of the graph as well as the editor in case something is set up incorrectly. Hope you can help, thanks in advance!



    I can't really figure out how to add images to the post... So I'll just post them as attachments
     

    Attached Files: