Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Official Puff of dust effects

Discussion in 'Open Projects' started by treivize, Nov 10, 2020.

  1. treivize

    treivize

    Joined:
    Jan 27, 2016
    Posts:
    136
  2. treivize

    treivize

    Joined:
    Jan 27, 2016
    Posts:
    136
    A new version slightly different:
    - dust impacts "aligned" with the steps
    - scale the dust cloud to be bent down like this 0 instead of o
    - color change to be more ground dust
    Puff_of_dust_2.gif
     
  3. erizzoalbuquerque

    erizzoalbuquerque

    Joined:
    Jan 23, 2015
    Posts:
    50
    Hey! Nice work! Are you using sprites or some kind of mesh for these particles?
    I personally prefer more rounded puff clouds since the characters are also more rounded, but you proposition still works very well. The darker color certainly made it more grounded.

    However, I think there was already a thread about particle effects in https://forum.unity.com/threads/particle-effects.980808/

    I don't know what should be done about it
     
    Last edited: Nov 12, 2020
  4. erizzoalbuquerque

    erizzoalbuquerque

    Joined:
    Jan 23, 2015
    Posts:
    50
    I started working on the landing particles yesterday inspired by the ones in Mario Odyssey (not the ideal gif to see the landing particles but the best I found)



    It seems they use a mesh not spites for the dust since they can cast very detailed shadows and I'm pretty sure you can turn the camera around the particles too.

    I came up with this result, using a puff model that I created and some simple animations.



    What do you think, people?

    It seems that in Mario the clouds keep changing their form but I don't know how to achieve this. I have little experience with particles. Any idea?
     
    Lashes, Erethan and treivize like this.
  5. erizzoalbuquerque

    erizzoalbuquerque

    Joined:
    Jan 23, 2015
    Posts:
    50
    I also implemented the jumping particles using the same concept

    Here's the result. What do you think?



    They are 4 particles system with different start delays.

    upload_2020-11-12_13-34-1.png

    Is there a better way to implement that?
     

    Attached Files:

  6. treivize

    treivize

    Joined:
    Jan 27, 2016
    Posts:
    136
    Hey @erizzoalbuquerque! Sorry about that, I missed the "Particle effects" thread when browsing the existing threads about this topic, I was looking for something with a title matching the card title...

    I guess @cirocontinisio will soon merge these threads together and define the result as the official thread for the codecks card related to puff of dust/particle effects.

    Your proposal might be more suitable for the game mood, a friendly game about cooking. Mine is a bit too "Japanese anime style" so, maybe too serious action style.

    Actually, I am programmatically instantiating a prefab cloud like mesh with a custom shader doing vertex displacement to make it a bit random and alpha dissolving to make it disappearing during the effect life time.

    Yours is already great! Maybe adding some rotation over time might help and to animate the form with sprite sheet you can use "Texture Sheet Animation"

    For the jump effect, I think you can use one particle effect and use Simulation mode to World to make them independent from the particle caster (pig's feet) :)
     
  7. erizzoalbuquerque

    erizzoalbuquerque

    Joined:
    Jan 23, 2015
    Posts:
    50
    Hey @treivize ! Thanks for the feedback!

    Interesting. So you used a vertex shader... I imagined there were fancier things than the default particle system. The particles "aligned" with the footsteps are a nice touch too. I'm using this project as a way to learning more about vfx and shaders (I know very little)

    But can I use "texture sheet animation" to fake the puff cloud deforming? Maybe I could use a vertex shader but I'm not very confident about doing that while maintaining the toon visuals from project.

    I'm already using the World Simulation Mode. I had to use multiples particles systems so each cloud has a start size smaller than the prior.

    Thanks for the advices. I'll try to make my own version of the running particle and I'll post here.
     
  8. treivize

    treivize

    Joined:
    Jan 27, 2016
    Posts:
    136
    Actually you can just derive the Toon shader to a new one like done for Toon_Wind one. Shader graph unlit shader give you the capability to deform geometry also:

    upload_2020-11-12_21-35-16.png

    Did you try to use "Start Size" from a curve?
    upload_2020-11-12_21-38-35.png
     
    erizzoalbuquerque likes this.
  9. erizzoalbuquerque

    erizzoalbuquerque

    Joined:
    Jan 23, 2015
    Posts:
    50
    Oh, so how this kind of stuff is done! Make sense. Thanks!

    It works! As always thought this curve was a probability curve (probability X size). Actually, is size over time! Much more useful! I can use that! Thanks


    I'm also having a strange high tri count. Each puff cloud mesh has approximately 300 triangles. And I have at most 10 particles at the same time on the screen. When I turn on the particle system I'd expect to have an additional 3000 tri count (300 x 10 particles), but it's reaching 10000. I don't know why this is happening. It's not significantly affecting performance. By far. But it's not what I expected.
     
  10. erizzoalbuquerque

    erizzoalbuquerque

    Joined:
    Jan 23, 2015
    Posts:
    50
    So I implemented a walking particle and coded some logic so I could see the particles in action. I don't intend to push the code since it's just a hack that doesn't follow any good practices and never should be seen by anyone but me :)

    Here's the result:



    Any thoughts?

    I used a smaller outline value because the outline would make the clouds very noisy when the camera is far from the character.

    Should I wait for any kind of feedback from @cirocontinisio ? Or can I open already open a pull request? This is my first PR on this project.

    Thanks for the help;
     
    itsLevi0sa and cirocontinisio like this.
  11. erizzoalbuquerque

    erizzoalbuquerque

    Joined:
    Jan 23, 2015
    Posts:
    50
    I don't mind creating a more formal particle logic right now, but there's no task for this on the roadmap, and maybe it's a bit too soon since the character logic is not very well defined yet.
     
  12. treivize

    treivize

    Joined:
    Jan 27, 2016
    Posts:
    136
    Hi @erizzoalbuquerque!

    I really like the landing effect, the two others might need some tweaks: Making the particles more random in position and time of appearance maybe.

    Maybe to help @cirocontinisio to validate the graphical direction, it might be a good idea to create a PR where your effect is attached to the main character. Anyone will be able to play with it and give feedback on it.
     
    cirocontinisio likes this.
  13. erizzoalbuquerque

    erizzoalbuquerque

    Joined:
    Jan 23, 2015
    Posts:
    50
    Thanks, @treivize I'll try to tweak more the jumping and walking effects. I'm not sure about adding a bit of time randomness to walking particles since the pig steps are constant, but I can try it out.
    I'll also open a PR (tomorrow) so the community staff can give it a review.
     
  14. erizzoalbuquerque

    erizzoalbuquerque

    Joined:
    Jan 23, 2015
    Posts:
    50
    I created a PR and I'm waiting for it to be reviewed.
     
  15. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Thanks for the PR, @erizzoalbuquerque! The effect looks good, I just want to double-check how many polygons is each of those cloud puffs, but other than that it should be ok.

    Also I need to make sure the effect is "wired" into our existing StateMachine solution, which is currently being reworked (but almost there).
     
  16. erizzoalbuquerque

    erizzoalbuquerque

    Joined:
    Jan 23, 2015
    Posts:
    50
    Thanks! @cirocontinisio ! I really don't have idea of how many polygons is too much for a particle. My model has 300, I think. Maybe it's too much, even if the number of particles is not greater than 15.

    I did the script to control the particles as a temporary solution to test the particles. The code works without changing any other file but probably comparing the current state strings to decide to play the particles it's not a very well-designed code hehe If there's any feedback on how to integrate it better with the state machine I can recode it in the intended way
     
    cirocontinisio likes this.
  17. treivize

    treivize

    Joined:
    Jan 27, 2016
    Posts:
    136
  18. erizzoalbuquerque

    erizzoalbuquerque

    Joined:
    Jan 23, 2015
    Posts:
    50
    Hey @treivize ! I will have a look at the PR. This refactor is really important. The script I did was just a temporary terrible hack to see the particles working. At the time I did it, the State Machine was just beginning to take form, and I thought that thinking about a more permanent solution would be useless. So I wrote a quick little ugly code to wire the effects to the character :)
     
    treivize likes this.
  19. treivize

    treivize

    Joined:
    Jan 27, 2016
    Posts:
    136
    Ok, I have updated my PR with an implementation solving all the points you raised except the first one (landing effect based on falling speed of the character)

    It took me a while to get familiar with the pools/factories but at the end they are very simple to use and to integrate! wow!

    I basically created a new PariticleEffectFactorySO taking a ParticuleSystem prefab as SO param and then created 3 factories one for each effect (the SO files are under ScriptableObjects/Pools/ParticleEffects:

    upload_2020-12-11_15-47-34.png

    Next I have created simple (the same as shown in the Pool Example) ParticleEffectPools for each of them:
    upload_2020-12-11_15-48-54.png

    Next I have replaced the usage of the Particle Prefab in the action PlayParticuleEffectSO to use the proper pool SO and added a Transform input to position/rotate/scale the effect based on a provided Transform from a prefab (is it fine to configure the effect positioning like that?)
    upload_2020-12-11_15-50-35.png

    In the action script, I have used the pool as following:

    Code (CSharp):
    1.  
    2.     private void TriggerParticuleEffect()
    3.     {
    4.         _particles = _parentSO.particlePool.Request();
    5.  
    6.         _particles.transform.SetParent(_stateMachine.transform);
    7.  
    8.         _particles.transform.localPosition = _parentSO.anchor.localPosition;
    9.         _particles.transform.localRotation = _parentSO.anchor.localRotation;
    10.         _particles.transform.localScale = _parentSO.anchor.localScale;
    11.  
    12.         _stateMachine.StartCoroutine(TriggerEffectCoroutine(_particles));
    13.     }
    14.  
    and in the coroutine, instead of destroying the particle system, I call the pool Return() method:
    Code (CSharp):
    1.  
    2.     private IEnumerator TriggerEffectCoroutine(ParticleSystem particleSystem)
    3.     {
    4.         particleSystem.Play();
    5.         while (particleSystem.IsAlive())
    6.         {
    7.             yield return null;
    8.         }
    9.         _parentSO.particlePool.Return(particleSystem);
    10.     }
    11.  
    upload_2020-12-11_16-1-58.png

    It works very well the particle system of each effect are created into a pool in the hierarchy the first time they are needed, attached to the character before playing and move back un-active in the pool at the end! Awesome @davejrodriguez!
     
    Last edited: Dec 11, 2020
    davejrodriguez likes this.
  20. metakazz

    metakazz

    Joined:
    Dec 18, 2020
    Posts:
    3
    Hey, y'all. This is my first Unity forum post and I'm super excited to start contributing to this project!

    I noticed that on Codecks there's a task for syncing the amount of particles emitted based on fall speed.

    I was wondering if anyone has already done this/started on it/ (is this even the right place to ask this?).
    Thanks in advance.
    upload_2020-12-18_14-37-31.png
     
  21. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    I don't think anyone is, no. And you can keep the discussion in this thread :)
    How are you thinking of implementing it? (presuming you have looked at the code already...)
     
  22. metakazz

    metakazz

    Joined:
    Dec 18, 2020
    Posts:
    3
    I actually just finished a working version that I'm happy to get feedback on.

    After looking at how particles are created, I made an overload of the existing method "PlayLandParticles" that takes argument called "intensity".

    Code (CSharp):
    1.     public void PlayLandParticles(float intensity)
    2.     {
    3.         // make sure intensity is always between 0 and 1
    4.         intensity = Mathf.Clamp01(intensity);
    5.  
    6.         var main = _landParticles.main;
    7.         var origCurve = main.startSize; //save original curve to be assigned back to particle system
    8.         ParticleSystem.MinMaxCurve newCurve = main.startSize; //Make a new minMax curve and make our changes to the new copy
    9.  
    10.         float minSize = newCurve.constantMin;
    11.         float maxSize = newCurve.constantMax;
    12.  
    13.         // use the intensity to change the maximum size of the particle curve
    14.         newCurve.constantMax = Mathf.Lerp(minSize, maxSize, intensity);
    15.         main.startSize = newCurve;
    16.  
    17.         _landParticles.Play();
    18.  
    19.         // Put the original startSize back where you found it
    20.         StartCoroutine(ResetMinMaxCurve(_landParticles, origCurve));
    21.  
    22.     private IEnumerator ResetMinMaxCurve(ParticleSystem ps, ParticleSystem.MinMaxCurve curve)
    23.     {
    24.         while (ps.isEmitting)
    25.         {
    26.             yield return null;
    27.         }
    28.  
    29.         var main = ps.main;
    30.         main.startSize = curve;
    31.     }
    32.     }

    I then rigged the "PlayLandParticlesActionsSO" to call the method with the intensity argument. The intensity is calculated based on how far the player fell during the State it was in.

    Code (CSharp):
    1. public class PlayLandParticlesAction : StateAction
    2. {
    3.     //Component references
    4.     private DustParticlesController _dustController;
    5.     private Transform _transform;
    6.  
    7.     private float _coolDown = 0.3f;
    8.     private float t = 0f;
    9.  
    10.     private float _fallStartY = 0;
    11.     private float _fallEndY = 0;
    12.     private float _maxFallDistance = 4; //Used to adjust particle emission intensity
    13.  
    14.     public override void Awake(StateMachine stateMachine)
    15.     {
    16.         _dustController = stateMachine.GetComponent<DustParticlesController>();
    17.         _transform = stateMachine.transform;
    18.     }
    19.  
    20.     public override void OnStateEnter()
    21.     {
    22.         _fallStartY = _transform.position.y;
    23.     }
    24.  
    25.     public override void OnStateExit()
    26.     {
    27.         _fallEndY = _transform.position.y;
    28.         float dY = _fallStartY - _fallEndY;
    29.         float fallIntensity = Mathf.InverseLerp(0, _maxFallDistance, dY);
    30.  
    31.         if (Time.time >= t + _coolDown)
    32.         {
    33.             //_dustController.PlayLandParticles();
    34.             _dustController.PlayLandParticles(fallIntensity);
    35.             t = Time.time;
    36.         }
    37.     }
    38.  
    39.     public override void OnUpdate() { }
    Would this be a good time to make a pull request or does it need reworking?
     
    cirocontinisio likes this.
  23. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Looks good! As a small optimisation, I don't think you need to reset the startSize in the Coroutine, since it will be always overwritten on every landing anyway? You would never use the original ever again.

    If you tested it and it works, make a PR for it!
    Make sure to test extreme cases, like a jump up (the player lands higher than they jumped from), when hitting the head under a structure (try the scene
    TestingGround_small.unity
    ) and so forth...
     
    metakazz likes this.
  24. metakazz

    metakazz

    Joined:
    Dec 18, 2020
    Posts:
    3
    I went ahead and opened a PR and addressed your point there. I figured it was better than typing it out twice. Thanks so much for the feedback, Ciro. I look forward to making more contributions!
     
    cirocontinisio likes this.
  25. cirocontinisio

    cirocontinisio

    Joined:
    Jun 20, 2016
    Posts:
    884
    Thanks David, I merged it!
     
    metakazz likes this.