Search Unity

Spawn particles with the rotation of the emitter...

Discussion in 'General Graphics' started by Rodolfo-Rubens, May 6, 2017.

  1. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,168
    ...using Simulation Space World, I can get the desired rotation I want by choosing to simulate based on Local space but I need the already spawned particles to be left behind because the emitter is moving, but I also need that the particles gets spawned with the same rotation of the emitter.

    Is there a way to do this? It's a pretty basic thing, but I can't find a way to do it...
     
    Last edited: May 6, 2017
  2. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    218
    you're trying to spawn particles in world space like a trail for a comet but still inherit the rotation of the emitter?
     
  3. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,168
    Yes, I want it to inherit the rotation of the emitter (to be more correct, the ParticleSystem is nested under another two objects, but I want to inherit its world space anyway). I'm trying to make footsteps, I was spawning quads and destroying them but I want to use particles for it instead because it's more perfomant.
     
    Last edited: May 6, 2017
  4. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    218
    yah that won't work the way you want.


    you'll want to spawn an emitter outside your characters hierarchy based on foot location according to an event and use local_space. foot steps that use the same material will batch
     
    theANMATOR2b and Rodolfo-Rubens like this.
  5. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,168
    I got it!! Every time I call play on my particle system, before, I set the startRotationY of them to my character's Y euler angle, it works!

    I will start a feedback entry for world space particles inherit emitter rotation though.
     
    Last edited: May 6, 2017
    Torbach78 likes this.
  6. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    218
    awesome that you got the code skills to do it.

    but wait I think align_to_direction is what you want in the *shape* tab. i think this was added to allow you to fling a deck of cards in an arc. Eh it's not working the way you'd want either
     
    Last edited: May 6, 2017
    Rodolfo-Rubens likes this.
  7. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,168
    Ah, yes, this works! I spent 1 hour trying to understand how it works, it seems like it doesn't work with meshes, I was using a quad mesh and it was not aligning, I switched back to billboard now it works! Thanks a lot!
    The results:


    Edit: ah, nevermind, this way, the particles spawned previously changes their direction when the emitter changes too, I just want to inherit the rotation in the spawn process... I will need to set the startRotationY...
     
    Last edited: May 6, 2017
  8. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,888
    I've only briefly read all this, so, I may be wrong, but take a look at the Render Alignment in the Renderer module. Try setting it to Local.
     
    Rodolfo-Rubens likes this.
  9. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    218
    ezgif-2-97a8efc9a3.gif
    I tried a few combos of alignment in shape/render tab and they inherit rotation continuously rather than at birth only.
     
    Rodolfo-Rubens likes this.
  10. ifurkend

    ifurkend

    Joined:
    Sep 4, 2012
    Posts:
    350
    You probably not gonna like this, but updating the transform.eulerAngles of the particle system object to the 3D start rotation of the particle system is probably the most straightforward approach (may still need to +- 90deg of each axis to the resultant rotation). Of course it still requires using the "world" billboard alignment but you can disable the shape module which is pointless now.
     
    Rodolfo-Rubens likes this.
  11. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,888
    I've added an item to our roadmap to make this easier.

    In theory, I think you should use Align to Direction to achieve this. However, the problem is that this locks you into Local Render Alignment. This means future emitter rotations also rotate the existing particles, which you have discovered.

    What I think we need to do, is allow World Render Alignment in this mode too, so old particles aren't affected by new emitter rotations.

    For now, I hope one of the suggested workarounds gets you what you want! :)
     
    theANMATOR2b and Rodolfo-Rubens like this.
  12. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    218
    nice!

    i'm concerned when using mesh renderer ... well let's say I'm imagining a character throwing saw blades with slight start_rotation randomness + rotation over lifetime gyroscopic + pivot offset

    interaction between start_rotation + world_based + shape_align_*world* + rotation_over_life + pivot_offset **whew**
     
    Last edited: May 7, 2017
  13. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,888
    Haha yeah that's a lot of different factors to get working together!
     
  14. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,168
    Simulation Space Local is not an option for me since the particle system is nested in the character, this way if I set to local the particle will spawn with the same rotation of the feet (ok) but the character will "carry" those already spawned particles/footsteps with him, I have the shape module disabled because I don't want them to spawn within a space range, nothing new there, I want them to spawn in a fixed point.
    So my current setup is Simulation Space: World, no shape, BUT, the particles always gets spawned facing the world.forward so I using my third post's method, setting startRotationY (I'm using a custom mesh which is a quad facing up, can't remember why using horizontal billboard wasn't working for me) before calling Play().

    Yes, exactly what I'm doing. You have some cool particles btw!

    Maybe a "Align only at birth" bool?
    Thanks! The more options the best!

    Things can get a little messy, haha... but, as long as it works we are good!

    Thanks for the replies guys, everything is working now!
     
    Last edited: May 8, 2017
  15. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,168
    Oh, just one more thing, I needed to invert the sign of transform.eulerAngles.y * Mathf.Deg2Rad, I was getting a mirrored rotation, forward and back was alright but left and right was inverted, the value in the start rotation field was correct, but the particle rotation itself was mirrored.
     
  16. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    218
    well I couldn't leave it alone and in 2017.1.0.b3 (BETA) i got it working
    shoes_02.gif
    1. simulation space = World
    2. renderer>render_alignment = 'velocity'
    3. renderer>render_mode > Mesh = Quad
    4. start speed = .001 (< important to establish a minimal vector)
    5. start rotation 90,0,-90 **
    two emitters with offset timing, size 2:1 each uses an atlas image 0 and 1


    dont quite understand this
    upload_2017-5-8_12-18-33.png
    when the local rotation was 90,90,180 the blue/red shoes just don't get the velocity right and don't work.. very odd :(


    EDIT ** Start Rotation 90,0,-90 and the shoes are aligned correctly oriented for Stretch billboard ;0
    upload_2017-5-8_13-48-13.png
     
    Last edited: May 8, 2017
  17. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,888
    That's odd.. does a slightly higher start speed fix it?

    Nice job getting it working!
     
  18. Torbach78

    Torbach78

    Joined:
    Aug 10, 2013
    Posts:
    218
    no dice on speed,
    but local 0,0,0 now I got it, works fine
    use 3D rotation 90,0,-90 to get the quad rotated correctly ; (maybe a gimbal issue?)

    note* using velocity_over_lifetime [local] the issue presents as before with local rotation continuing to update (red shoes) upload_2017-5-8_13-31-42.png
    mm this would seem intended imo
     
    Last edited: May 8, 2017
  19. andreasng_pd

    andreasng_pd

    Joined:
    Oct 7, 2013
    Posts:
    13

    I dont see align to velocity anywhere in the renderer. You mention you choose mesh > quad, but there is no such thing. Well there is - but if i choose mesh then select a quad (also the standard quad) then that is still just an ordinary mesh.
    upload_2017-9-4_11-57-30.png

    upload_2017-9-4_11-57-7.png
     
  20. ifurkend

    ifurkend

    Joined:
    Sep 4, 2012
    Posts:
    350
    This mode is only available from Unity 2017.1, so update your editor.
    https://unity3d.com/get-unity/download/archive
     
  21. andreasng_pd

    andreasng_pd

    Joined:
    Oct 7, 2013
    Posts:
    13
    @richardkettlewell
    ""What I think we need to do, is allow World Render Alignment in this mode too, so old particles aren't affected by new emitter rotations.""

    this still does not work does it? I'm trying with meshes of smoke. I want to spawn them with the particle system transform alignment at birth and then leave them be after that.

    can't
     
  22. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,888
    No, sorry, we haven't added it yet.
     
  23. andreasng_pd

    andreasng_pd

    Joined:
    Oct 7, 2013
    Posts:
    13
  24. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,888
    It's on the roadmap, but not being prioritised at the moment.
     
  25. snoche

    snoche

    Joined:
    Feb 22, 2010
    Posts:
    80
    I was looking to do something similar too, I am using Unity 2018.3 Is not possible to align particles to direction yet?
     
  26. Buckslice

    Buckslice

    Joined:
    Sep 12, 2014
    Posts:
    5
    Not sure about 3D but I was able to get it working pretty easily in 2D. Made this script that continuously updates the particle start rotation to match the transforms rotation. Im guessing for 3D you would have to instead edit the 3D start rotation and also set the render alignment to world. Hope this helps!

    Code (CSharp):
    1. using UnityEngine;
    2. [RequireComponent(typeof(ParticleSystem))]
    3. public class ParticleAligner : MonoBehaviour {
    4.  
    5.     ParticleSystem ps;
    6.  
    7.     // Start is called before the first frame update
    8.     void Start() {
    9.         ps = GetComponent<ParticleSystem>();
    10.     }
    11.  
    12.     // Update is called once per frame
    13.     void Update() {
    14.         var main = ps.main;
    15.         main.startRotation = -transform.rotation.eulerAngles.z * Mathf.Deg2Rad;
    16.     }
    17. }
    18.  
     
  27. CosmicBoy

    CosmicBoy

    Joined:
    Apr 16, 2014
    Posts:
    33
    @Torbach78 Thank you so much for this, was doing my head in! ;)
     
  28. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    626
    Really weird shortcoming of the particle system. Looks like I'll have to handle it myself in code through manual emission.
     
  29. Cover-Club-Media

    Cover-Club-Media

    Joined:
    Apr 30, 2015
    Posts:
    97
    Huge shortcomings you're right. Trying to figure out how to implement some footsteps and the particle system has so many bugs in it. What a headache to do something so trivial. Unity's particle system needs way more attention to fixes.
     
  30. DungDajHjep

    DungDajHjep

    Joined:
    Mar 25, 2015
    Posts:
    95
    thanks ! its work.
     
    richardkettlewell likes this.
  31. AlcoleponeHome

    AlcoleponeHome

    Joined:
    Jun 9, 2018
    Posts:
    41
    is this going to get looked at again any time? still seems impossible to do a simple old school style boat wake, where the particles trail the boat using the initial direction and are flat/horizontal shaped
     
    Xain, FelixNicol and JasonSpine like this.
  32. FelixNicol

    FelixNicol

    Joined:
    Jul 18, 2021
    Posts:
    3
    This is exactly why I am here today! I'll try some of the scripting solution, but I was unable to do it built-in. Thanks for all those posts over the years, I better understand why I am struggling with this.
     
  33. Drannach

    Drannach

    Joined:
    Apr 6, 2014
    Posts:
    25
    ... and i want to bump this up, still cannot see a built-in solution, prioritize it Unitydevs!
     
  34. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    1,888
    You’re right, we should have this already. I’ve started work on it today. If it works out, it will be available in Unity 2022.2.
     
    SoftwareGeezers and DungDajHjep like this.
unityunity