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

ParticleSystem bug with inherit velocity?

Discussion in 'Scripting' started by Big_Friggin_Al, Apr 6, 2021.

  1. Big_Friggin_Al

    Big_Friggin_Al

    Joined:
    Jan 9, 2014
    Posts:
    36
    I have a project where I want a space ship to blow up, and the explosion particles to inherit the ship's velocity.

    I have the particle system parented to the ship, and call Play(), then unparent the particle system, then I remove the ship from the scene (all on the same frame).... and my explosion won't move!!

    However! If I wait even a single frame after calling Play() to unparent the particle system and remove the ship, then the explosion DOES move as desired.

    How can I have the explosion inherit velocity immediately, so I don't have to write code to allow the ship to live for an extra frame just to get this to work?
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Try calling Emit on the particle system to force the particles to fire immediately. Otherwise, it might just be a quirk of the particle system in general.
     
  3. Big_Friggin_Al

    Big_Friggin_Al

    Joined:
    Jan 9, 2014
    Posts:
    36
    Thanks but no, that doesn't change anything. The particles emit just fine on the initial frame (with either Play() or Emit()), but they don't seem to inherit the velocity of the parent until the subsequent FixedUpdate?

    Is this by design (because if so the docs are incorrect) or am I missing something?
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I found this thread with info on how it looks like the inherit velocity module works today:

    https://forum.unity.com/threads/par...velocity-changes-your-feedback-needed.411267/

    Relevant info:
    Since the local velocity doesn't come directly from the rigidbody, it must still be using the same velocity calculation mentioned earlier in the post, while using local space.
    So since local velocity needs both old position and current position, that sounds like it needs 2 frames before local velocity of the particle system can be calculated. So on the 2nd frame we now have local velocity, so we calculate the overall velocity by subtracting it from rigidbody velocity...... But oops!!! The rigidbody was destroyed at the end of last frame, so can't do the calculation. Without a parent, I think that breaks calculating local velocity on the 2nd frame as well.
     
    Last edited: Apr 7, 2021