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 Looking for a way to rotate particles around themselves based on a predefined position

Discussion in 'Visual Effect Graph' started by marcrem, Aug 12, 2022.

  1. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    Hi,

    I use a Sample Bezier node to position particles along a curve when they spawn. Now I would like them to rotate along the y axis at that position.

    Anyone have an idea? Maybe @VladVNeykov ?

    Here's my initialize particle module:
    upload_2022-8-12_3-0-21.png



    Here's how it looks like, you can see cubes where my points are:
    upload_2022-8-12_2-58-39.png

    You guessed it, I'm reworking my tornado and I want the particles to rotate around a point on that bezier curve.

    I'm kinda lost. I tried Rotate 3D but it doesnt respect the bezier curve.

    Thanks
     

    Attached Files:

  2. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hey @marcrem ,

    Here's an example of how you can do this:
    upload_2022-8-12_8-59-43.png

    This will get you something like this:

    You can also use the 0-1 value to change the rotation speed at different hights, the colors, etc.

    I've put together a small package here of the effect above.
    Hope this helps!
     

    Attached Files:

  3. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    Thank you so much! You are a savior. Any idea how to give particles an upward velocity that still follows that curve? it just needs to feel like it's going up a bit
     
  4. OrsonFavrel

    OrsonFavrel

    Unity Technologies

    Joined:
    Jul 25, 2022
    Posts:
    128
    If you're following Vlad Solution, you should be able to use the Tangent Vector Output from the Sample Bezier Block.
    Multiply it by some strength and use it as Velocity in the initialize Particle Context.

    upload_2022-8-12_18-11-15.png
     
  5. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    I tried using it in a set velocity node in the initialize context, but the particles don't exactly follow the curve. They actually offset themselves over time, so my tornado kinda doubles itself in waves
     
  6. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    We can move our two Set Positions to the Output, and then just increment the position on the bezier curve:

    I've also added a random gradient to visualize the result a bit better. With this, we get the following:


    As a bonus, this will also enable you to move the bezier control points :)

    Hope this helps!
     

    Attached Files:

  7. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    Thank you again so much! Great support as always.

    I've been trying to plug this into my vfx graph which contains some more controls like particle size relative to the width of the tornado, some randomness, etc.

    When I tried adding your "add value over lifetime" group and connect it to my system, it gave me really cool but weird results. Here's my graph if you wanna take a look, I feel like I'm missing something when simply replacing the output of the first modulo and plugging it into the new group before everywhere else.
     

    Attached Files:

  8. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hey @marcrem ,
    Is what you attached the latest? It's missing an output, the blocks are still in initialize, and it doesn't have the "add value over lifetime" group:
    upload_2022-8-15_9-46-50.png

    Either way, it might be missing things if it's not the latest, but I've added an output and integrated the bits into your effect (attached below). Btw, I quite like the directional change of the tornado you made! :)

    Hope this help!
     

    Attached Files:

  9. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    Thanks, I tried your package and it confused me a lot as almost everything was moved to the output node and I use a lit output node as well.

    It looks like not everything worked when I sent the vfx, so I made a package.

    Here's the features I added myself:
    - Particles scale up when the radius of the arc scales at that position
    - Rotation will go slower if the radius is bigger and faster if the radius is smaller
    - Particles are lit and are using a 4x4 sheet flipbook blend

    The effect looks like this:


    Notice how I can move my bezier points and it will follow but only the newer particles will spawn correctly, the old ones are not moved. Probably because they're not in the output node

    Thanks again :)
     

    Attached Files:

  10. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    So let's say I move my blocks to the output node, I solve the problem of moving the bezier points, it now works perfectly. However, something's suddently wrong with my particles, it looks like they're having a party with strobe lights :p

    Edit: I also used Total Time (VFX) in the "rotate around the bezier curve" instead of delta time like you mentionned.


    And then if I try to add the value to make them go up, this happens:
     
    Last edited: Aug 15, 2022
  11. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    Here's my latest package with what I mentionned above (Bezier works real-time, but everything flashes weirdly, and I can't get upward movement to work) in case you want to compare the 2 rendering results.
     

    Attached Files:

  12. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    It looks very close, just some of the values were a bit high.
    I've attached a package with smaller values and a few small connection changes
     

    Attached Files:

  13. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    Thanks again.

    I now have upward movement working, but there's some things I'm not sure why they are happening.
    upload_2022-8-15_22-14-5.png
    Your note here, you're dividing 0.05 by the lerp's value, and then doing nothing, so I'm unsure why it's there.

    Now here in the following screenshot, my add-on to make particles rotate slower when the radius is larger is gone:
    upload_2022-8-15_22-18-23.png

    Strangely, if I do what I had done (next screenshot), it does make it faster on small radius and slower on bigger radius, but suddently it rotates the other way around and I can't figure out why. It also slows it down way too much on the larger parts of the tornado:
    upload_2022-8-15_22-20-8.png

    Other than that, what really bothers me is why your screenshot doesn't show the "flashing" effect while mine still does.


    I know I'm asking a lot and I can't thank you enough! I really wanna understand what's going on there!
     
  14. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    I tried using this originally, but the values were just too high so I left a note (but it's confusing, yes, it's not needed, you can delete it :))

    It helps to visualize things. First, let's see what the distribution of that Lerp for the TopFunnelWidth / BottomFunnelWidth looks like. We can plug in the value from the Add a value over lifetime to move particles up group to a color gradient in the Output and visualize it:


    A linear interpolation between the top and bottom funnel width might not give you enough control to decide what part of the tornado should rotate at which speed (and it makes it at times harder to control two values to get the right look).

    We can explore a simpler approach by using a curve. You can control the overall speed with just your Rotation Speed property, and use the curve to determine the distribution along the length of your tornado:


    Here's how that looks in action by modifying the curve:


    Hm, maybe lowering the exposed Rotation Speed?


    No worries! I'm not able to spend as much time on the forums these days as I'd like, but happy to help :)
     

    Attached Files:

  15. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    Thanks, most of my issues are now fixed. Except that flashing effect that you clearly don't get on your side.
    Here's an example, I tried with a lot less particles at the beginning to show you how it's not rotating that fast. Then I add more particles and you'll clearly see my problem:
     
  16. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    Here's another example to illustrate my problem:
     
  17. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    Same setting with 30 particles instead of 300:
     
  18. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    One last video: Is this a bug? I turn on the coloring, and it slows down rotation? The VFX Graph is not even attached to the Visual Effect.
     
  19. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    Alright so it's really weird actually. Just noticed the rotation actually speeds up over time. Something has to be wrong on my side.

    I place my VFX prefab on the scene, speed is fine. I wait for about a minute and it's going about 2 times faster.

    The rendering bug where particles are drastically changing their lighting keeps happening no matter what.

    I tried to put my entire graph in a screenshot so it's visible without downloading a package. There has to be something I messed up, but I can't figure out why
     

    Attached Files:

  20. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Looks like there are two outstanding issues:

    Flickering:
    to narrow this down, let's check a few things.
    • Can you confirm that your flipbook is set right? (I see it's 6x5 - just to confirm it's not 5x6). Also what's the range of the Set Tex Index over Life curve in your Output? What happens if you disable flipbooks and just have the default texture - does it still flicker?
    • Can you play around with lighting; turn off shadow casting or change the output from lit to unlit (you can right click on the output and pick Convert Output:

    • A few other potential things to look into: check sorting, start disabling blocks one at a time in the output, and try reducing the capacity (just in case it's some local error).
    Rotation Speed increase
    • Yup, happens for me too! Looked into it, I think the second Total Time (VFX) is unnecessary, as we are already feeding time earlier in the logic so it was growing exponentially. Just remove this and increase the rotation value a bit:
     

    Attached Files:

  21. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    Flickering:
    My flipbook seems correct, here's the texture:
    Smoke30Frames.png

    The Set Tex Index over Life curve goes from 0 to 1 in X and 30 to 0 in Y (I wanted the animation to go in reverse).

    Now, when I disable shadow casting, the flickering still happens, but there is indeed no shadows. Weird thing though, when turning shadow casting back to ON, shadows are not working. I have to do CTRL + Z two times for them to be visible again:


    When converting the output to unlit, it still flickers:


    Now if I play with sorting, I don't see the flickering anymore when turning sorting OFF, but you can see particles that should be hidden by others:


    Now when reducing capacity, it doesn't change anything with the flickering (and of course down to a point, you can't see all the tornado anymore)

    I also tried disabling blocks but aside from either not rotating or not being at the correct position, no change in flickering.

    In case this helps, here's how it looks like when getting really close to it. It's as if each particle was trying to pop in front of each other:



    Thanks again!
     
  22. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi, tried on 2021.3 and am also getting the flickering you are seeing:

    (I stopped all rotation/upwards movement and replaced the flipbook with a numeric one to make it more obvious)

    Looks like a bug in 2021.3, I didn't reproduce it in 2022.2. I'm out of the office this week, but will check if it's something that was fixed in 2022.2 and whether it can be backported.
     

    Attached Files:

    whyatme, marcrem and Qriva like this.
  23. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    Thanks, I'm very glad I could help find this issue! I sincerely hope it can be hotfixed in 2021 as it's the mostly supported LTS right now and we're actually almost done with upgrading our project from 2019 to 2021, which wasn't fun times!

    Thanks for your time and enjoy your time off if that's what's keeping you out of the office for the week :)
     
    VladVNeykov likes this.
  24. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    Hi Vlad,

    Just wanted to ask, should I report this issue somewhere? Or did you mention it to the team? :) Thanks, hope all is well
     
  25. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi @marcrem :)
    No need, a PR is already made targeting 2021 which will stop the flickering. Our sorting is done in Update, looks like the issue here is that since we're not setting any position before, sorting is performed on (0,0,0) position causing the flicker.

    In the meantime, I played around with it a bit and there are a couple of workarounds.

    1. You can add any random position / shape block in initialize, or even better, duplicate the Arc Circle shape we have in the Output and move it to Initialize so the sorting will be close to what we are setting in Output anyway, and that should stop the flickering. Still, your sorting will be probably incorrect (the PR in question will address the flickering, but the sorting will still be incorrect since it's done in Update).

    2. (Preferred) Technically this all goes away if we are setting the circle in Update (so the new positions will be sorter properly), but the Set Position (Shape) blocks currently don't have a random constant option, which will cause a different kind of flickering - particles will get a random new position on the circle each frame. With some position blocks that really complicates things, but with circle, we can relatively easily adjust this:


    - Move both the Set Position (Shape: Arc Circle) and the Set Position blocks from Output to Update
    - Set the Spawn Mode of the first block to "Custom"
    - Create a Random Number operator, make sure it's Per Particle and set to Constant with a value of 0-1 and plug it in the Arc Sequencer input.

    This should resolve your issue and prevent the flickering. Here's what I'm seeing in 2021.3:


    Hope this helps! :)
     

    Attached Files:

  26. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    THANK YOU SO MUCH! Very lucky to have you here to help :) That fixed it.
     
    VladVNeykov likes this.
  27. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    Now how would I, using this setup, keep some of my particles and only use those aside on a block while the others are still doing that ?
     
  28. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Happy this solved it!

    I'm sorry, couldn't quite understand what you mean by this; can you please elaborate?
     
  29. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    My bad.

    I would like to "reserve" some particles for a dust cloud on the ground, so they don't get placed in the tornado. And then I would like these particles to be affected by a vector field, for example.

    However, I'm not sure where I should split the particles to keep some for my dust cloud, and then I also don't quite understand how you can place a block like vector field force, and only have some particles be affected by that block, not every one of them.
     
  30. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Ah, gottcha!

    There are a few ways you can do this. It's best if the particles are part of the same output/system, so they can correctly sort with each-other, else your dust cloud will be always either in front or behind the tornado.

    First, you can single out some particles. Here, we are grabbing every 50th particle and telling it that it's special (which is rather nice). We can store this data in any attribute, but to keep it clean, we can create a new Set Custom Attribute block, change it's type to be bool, and name it isSpecial.


    Then we can add a Get CustomAttribute operator, set it to match our isSpecial name and bool type, and branch out in Update what we want to do. Here's a simple example of setting a new position:


    And the result:


    For any force blocks, they are just setting the velocity attribute which automatically gets added to the particle position. You can create your own logic here.

    You can first off disable this automatic position update from velocity by selecting your Update context and unticking Update Position in the inspector:

    (note this option will only be visible if you have something modifying velocity in your graph - a set velocity block, Vector Field Force, turbulence, etc.)

    Then you can store this new velocity-updated position in another variable and add it to your special particle's position:
     

    Attached Files:

  31. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    I ran out of attachments per post, but the final result can give you particles in the same effect, but behaving distinctly differently.


    You can use the isSpecial attribute to also make the ground dust particles larger, a different color, etc.
    Hope this helps! :)
     

    Attached Files:

  32. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    Thank you :) I will work with that. Again, 10/10 incredible support <3
     
    VladVNeykov likes this.
  33. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    Hi again @VladVNeykov :)

    I made a dust cloud at ground level, and it has its own bezier curve, pretty much the same system as the main tornado.

    I am looking for a way to create some sort of turbulence or distortion in it now to simulate this:



    It's pretty much as if the dust cloud was made of multiple vortex dancing around each other. Doesn't have to be that precise, but that's kind of the feeling I'm looking for. Ideally, I'd have a multiplier from 0 to 1 that would enable or disable this "turbulence".

    Any idea?
     
  34. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi @marcrem,
    Apologies for the delay, I've stepped away from the VFX Graph and am focusing on other things within Unity so I am not on the forums as much anymore :)

    To confirm do you just want to add some noise across the whole system, just across a part of it, or to split it into a number of smaller tornadoes that still resemble the big one?

    (I'm just about to take some time off, so will take a look when I'm back)
     
  35. marcrem

    marcrem

    Joined:
    Oct 13, 2016
    Posts:
    336
    In the end, I'd like to have a float/slider from 0 to 1 that will affect the dust cloud only. at 1, the dust cloud would be made of multiple small vortex rotating around the main axis appearing and disappearing randomly with noise, and at 0, it would be a regular thick dust cloud like it already is. I thought maybe with some noise/tubulence (no idea how though) I could get an effect that makes it look like there's small vortex without actually making small vortex, but whatever makes it look close to my reference would be awesome.

    No worries for any delay, I very much appreciate the help you gave me. Enjoy your time off!