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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question Moving element with particle system spawn them between positions

Discussion in 'Scripting' started by mavv, May 17, 2020.

  1. mavv

    mavv

    Joined:
    Feb 4, 2014
    Posts:
    29
    So when I change position on long distance for object at once, particles can be spawned between positions. Just imagine Player with torch entering to portal, teleport to other portal, but some of fire from torch is spawned middle way.
    I wroted some script for avoid this, and it solved problem, but Im wondering, maybe it isn't necessary?

    No, Local space for particles don't solve it, because then torch fire will look glued to player :)
    It's my bad thinking, or it can be consider as bug?

    script:
    Code (CSharp):
    1. private ParticleSystem[] wrap_ps;
    2. private Queue<bool> wrap_bool = new Queue<bool>(); // FIFO
    3. private ParticleSystem.EmissionModule wrap_em;
    4.  
    5. public void move_object(Transform obj, Vector3 new_pos){
    6.     wrap_ps=obj.GetComponentsInChildren<ParticleSystem>();
    7.     if (wrap_ps.Length>0)
    8.         foreach (ParticleSystem ps in wrap_ps)
    9.         {
    10.             wrap_em=ps.emission;
    11.             wrap_bool.Enqueue(wrap_em.enabled);
    12.             ps.Pause();
    13.         }
    14.    
    15.     obj.transform.position=new_pos; //there is our "teleport"
    16.    
    17.     if (wrap_ps.Length>0)
    18.         foreach (ParticleSystem ps in wrap_ps)
    19.             if (wrap_bool.Dequeue()) ps.Play();
    20. }
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,240
    It’s deliberate :) turning off the emission module or pausing the effect while teleporting seems like a good solution to me
     
    karl_jones likes this.
  3. mavv

    mavv

    Joined:
    Feb 4, 2014
    Posts:
    29
    To be more fair, this was my first idea, but don't worked:
    Code (CSharp):
    1. wrap_em.enabled=false;
    2. //// teleport and other stuff
    3. wrap_em.enabled=true;
    because particles still was spawned. .Pause() must work different.