Search Unity

Particle System Distance Rate + RigidBody 2D

Discussion in 'Editor & General Support' started by Tsequier, Dec 12, 2016.

  1. Tsequier

    Tsequier

    Joined:
    Apr 20, 2016
    Posts:
    23
    Hello !
    I'm having an issue with the new Unity 5.5: my particle system doesn't emit over distance when not moved with physics if a rigidbody2D is attached to it (if I only do transform.Translate, it does Emit if my object does not have a rigidBody2D component attached), I don't know if I am the only one but it's troublesome !

    If anyone have an idea on how to overcome this I'll be happy !

    Thanks !
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    This is because we now use a Rigidbody to drive the velocity of the particle system if one is attached.
    Previously the particle system would calculate the velocity for itself however if a rigid body was attached then the rigibody and the particle system would have 2 different velocity values due to the 2 systems updating the values at different times(fixed update etc) which would cause particles to behave incorrectly. If you want to move the system you need to do it through the rigidbody by changing its velocity. You could also try making the particle system a child of the rigidbody, it will then calculate a local velocity based on position and apply that to the rigibody velocity which should achieve what you want.
     
    charley3d likes this.
  3. Tsequier

    Tsequier

    Joined:
    Apr 20, 2016
    Posts:
    23
    I see, I'll try this, thanks for the quick reply !
     
    karl_jones likes this.
  4. mercuron

    mercuron

    Joined:
    May 11, 2015
    Posts:
    2
    Hi,
    For me it did not work to add the ParticleSystem as child to the RigidBody, but the other way round.
    I use touch gestures to move a GameObject with RigidBody2D and ParticleSystem attached. The ParticleSystem emits over distance. This was broken in Unity 5.5.
    I tried to make the ParticleSystem a child of the RigidBody2D as suggested above, but the emission still did not work. Now I moved the ParticleSystem back to the main GameoObject and made the RigidBody2D a child. This seems to work.
    Hope this helps.
     
  5. Juande

    Juande

    Joined:
    Nov 20, 2012
    Posts:
    16
    evyviggy and kaledom like this.
  6. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    If the effect does not work anymore then please report it as a bug. Although I was told about this issue with the tanks tutorial and tested it myself a month ago and it worked fine, have you tried the completed version of the tutorial?
     
  7. big_march

    big_march

    Joined:
    Mar 2, 2015
    Posts:
    38
    Hi. I make the particle system a child of RigidBody, then move the RigidBody by using rigodBody.MovePositoin(), but the particle system still not work at all. I have to make the particle system "out of the RigidBody" (Not a child), and update its position in Update(), it works but this is not a good way to do like this. Is it any way to solve this?
     
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    I'm not sure I understand. Can you file a bug report with a sample project that shows this problem?
     
  9. big_march

    big_march

    Joined:
    Mar 2, 2015
    Posts:
    38
    Please check the attach file.
    In the example scene, I made the particle system as a child of the rigidbody object, but the particle system didn't emit when its parent moving. (I made the rigidbody object moving by using "RigidBody.MovePosition()")
    Thanks for help:)
     

    Attached Files:

  10. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    Hi. Can you file this as a bug report please? I can get QA to look at it then, otherwise Ill try and take a look when I get a chance but may end up forgetting about it :(
     
  11. big_march

    big_march

    Joined:
    Mar 2, 2015
    Posts:
    38
    Sorry for my late reply. I've reported a bug(900069). Thanks for your help.
     
    karl_jones likes this.
  12. stylophone

    stylophone

    Joined:
    Aug 16, 2012
    Posts:
    37
    This is actually a very old bug which first occurred in my project was about 3-4 months ago. My solution was has an empty container for the two objects separately has rigidbody and particle system attached. And then move the container. It works at first place but still doesn't make sense to me for a long time. So I googled this topic and hope this bug could be fixed asap.
     
    Last edited: Apr 14, 2017
  13. NLongchamps

    NLongchamps

    Joined:
    Sep 9, 2014
    Posts:
    10
    Also currently going through the tank tutorial, and when moving the tank using "RigidBody.MovePosition()", the RB component reports a velocity of 0,0,0 when i poll it with debug log. Don't know why particles get spawned when rotating, but this depends on the particle object being off-center of the parent. If you reset xform on the particle child object, it will fail to spawn particles both when translating and rotating.
     
  14. Meganion

    Meganion

    Joined:
    Nov 24, 2014
    Posts:
    3
    Hey guys,
    I've sufffered with this problem when i've tried to update from 5.4 to 5.6, i'd searched through stack overflow and some other forums but nothing...
    Then i've decided to solve it with the solution below.
    This is happening because the particle system someway is being affected by dynamic rigidbody and it becomes directly dependent of the FPS(Try to decreace or increace and you will see it).
    To resolve there are some ways, the last one is the most correct in my opinion.

    1st, Create a particle that uses rate over distance out of the parent and make follow it.
    (as i've made before like stylophone)

    2nd, Put an Knematic not simulated (not affected by physics) rigidbody on the game object responsbile by the particle.



    Before

    After

    .
     
  15. ifurkend

    ifurkend

    Joined:
    Sep 4, 2012
    Posts:
    350
  16. Meganion

    Meganion

    Joined:
    Nov 24, 2014
    Posts:
    3
    Oh, i didn't see it, but if i'm not wrog, you were changing the velocity of the gameobject to 0 on late update in your solution, right?. you were using an particle outside the rigidbody2d following target right?.
    On 5.6 the boolean simulated it is in the inspector, in your video it wasn't.
    (but still in doccumentation at least from 5.0)
    In my specific case, i use addforce to move my spaceship, soo i would had to do it(make particles out of them following) my spaceship and a bunch of enemies it would flood the hierarchy, using as an child inside and rigidbody with an knematic not simulated it became more clean in my opinion for my situation.
     
  17. ifurkend

    ifurkend

    Joined:
    Sep 4, 2012
    Posts:
    350
    I am not entirely sure about "changing the velocity of the gameobject to 0", but it is correct that my solution requires that the PS is not parented to any object with RB component. Because you're copying the world position (instead of local position) of the RB object to the target PS object, it doesn't matter where that PS object is positioned on awake.
    The solution with "is knematic" was an answer I got from a Unity technician, may be Karl?
    If emission over distance is functional but simply not perfectly as expected, you should instead enable any interpolation option in the RB component first.
     
  18. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    Hi. To clarify a little.

    If a particle system detects a non-kinematic rigidbody then it will use the velocity value from this instead of attempting to calculate the velocity itself.
    The reason for this is because of the different update times for particles and physics which at high speeds would cause particles to calculate a different velocity from the RB and particles would fly off in the wrong direction, by staying in sync with the RB we avoid these strange issues.

    If a RB is driving the velocity you will see this message in the inspector:
    upload_2017-4-19_14-9-37.png

    In older versions the message is in the inherit velocity module but we recently moved it to the main module.

    RigidBody.MovePosition() will not work as it does not update the velocity when using this(by design). So if you are using MovePosition then either mark the RB kinematic(so it's ignored) or switch to setting the velocity instead.
    For moving vehicles etc you should really be using velocity, MovePosition is for teleporting which is why velocity is ignored. I have not recently looked at the Tanks tutorial but it's possible that the team that developed it did not realise this, which is why it is not working with particles correctly anymore.

    For example the bug project submitted by @big_march.
    You can fix it by setting the velocity instead like so:
    Code (CSharp):
    1.     void FixedUpdate()
    2.     {
    3.         Rigidbody rb = GetComponent<Rigidbody>();
    4.         //rb.MovePosition(rb.position + transform.forward * Speed * Time.fixedDeltaTime); // This won't work
    5.         rb.velocity = transform.forward * Speed; // This will work
    6.     }
    We also detect what we call local velocity for child systems. So if a particle system is moving whilst also parented to a RB then we calculate the delta difference and apply this to the RB velocity to get the child velocity. This is why you may sometimes see particles emitted even when the RB has zero velocity.

    So in summary:
    -If moving a non-kinematic RigidBody then do so by setting the velocity value unless you want to teleport in which case use MovePosition.
    -If the RigidBody is kinematic then the particle system ignores it and does its own calculations.
     
    Last edited: Apr 19, 2017
    big_march likes this.
  19. flayedone

    flayedone

    Joined:
    Sep 18, 2015
    Posts:
    1
    Hey guys, sorry to resurrect this by a few months.

    I was working my way through the Tanks! tutorial as well and ran into this dust trail problem. I solved it by setting the velocity as mentioned above. However, later on, when the exploding shell should have pushed the tank, it didn't work as expected. The tank just teleported a short distance rather than appearing to roll backward.

    After reading karl jones' reply, I created another empty game object (called Dust) as a child of the Tank object. I then moved the two dust trail objects so that they were a child of Dust. I added a Rigidbody to Dust and checked "is Kinematic". This allows the dust trails to work and the tank to be pushed back as expected by the exploding shell.

    This is probably not ideal, but it gets the same behavior as the tutorial without any script changes.
     
    unity_94d33m and GreeneMachine like this.
  20. edilbertoaq

    edilbertoaq

    Joined:
    Dec 24, 2015
    Posts:
    3
    Totally right there, I had my missiles with rigidbodies because I was instantiating them as rigidbodies from code. Therefore the particle systems stopped working from Unity 5.5.0 up.
    Now I removed the rigidbodies from the missiles prefabs and instantiate them as just as GameObjects. And the particles came back again.
     
  21. sirleto

    sirleto

    Joined:
    Sep 9, 2019
    Posts:
    146
    i have had this same problem in 2021 (using unity 2019) and i read this thread and https://answers.unity.com/questions/1291371/unity-550-particle-system-emission-module-rate-ove.html

    i found the described behavior logical but the solution(s) confusing.

    what i did was this:

    1. as a "bullet" i am having a particle effect with "emission: rate over distance" with non-kinematic rigidbody (parent). it worked well even though it has the above described situation.
    2. i added a "homing" effect, by putting a Rigidbody.AddForce() in (Fixed)Update() which required me to set Rigidbody.Velocity() to zero or else my homing wouldnt work.
    3. with this change the particle effect was lost (not emitting anything)
    4. what i needed to do to solve it was now this:

    rb.velocity = this.transform.forward * my_custom_speed * Time.fixedDeltaTime;

    so as a summary: having the rigidbody was no problem. starting it with AddForce() was no problem. but adding homing effect with AddForce() in each FixedUpdate() AND setting velocity manually to zero (which is maybe stupid, i dont know, it just worked for me) caused the velocity to stay zero. setting the velocity manually worked, but only when i multiplied it by Time.fixedDeltaTime (because its a physics effect).

    hope this helps someone else :)

    feel free to tell me where my whole logic is stupid, i would love to learn to do it better :)