to move Particles of Particle System from one point to another.

I have one question. I want the Particles I created with Particle System to go from one point to another and I want it to do it at a certain speed. But it either doesn’t move to the position I gave it at all or it goes very fast, it seems like it’s teleporting. How can i fix it?

public class PartCollecter : MonoBehaviour
{

    public ParticleSystem ps;
    List<ParticleSystem.Particle> Parts = new List<ParticleSystem.Particle>();
    public GameObject TargetObj;

    ParticleSystem m_System;
    ParticleSystem.Particle[] m_Particles;

    public float m_SmoothTime = 0.5f;
    public float m_Speed = 10;
    Vector3 m_Velocity;



    // Start is called before the first frame update
    void Start()
    {
        Invoke("Move", 2f);
    }

    private void Update()
    {
       
    }

    public void Move()
    {
        if (m_System == null)
            m_System = GetComponent<ParticleSystem>();

        if (m_Particles == null || m_Particles.Length < m_System.main.maxParticles)
            m_Particles = new ParticleSystem.Particle[m_System.main.maxParticles];

        int numParticlesAlive = m_System.GetParticles(m_Particles);

       
        for (int i = 0; i < numParticlesAlive; i++)
        {
            m_Particles[i].position = Vector3.SmoothDamp(transform.position, TargetObj.transform.position, ref m_Velocity, m_SmoothTime, m_Speed * Time.deltaTime);
           
        }

        m_System.SetParticles(m_Particles, numParticlesAlive);
    }

}

You are using the same m_Velocity for ALL of your particles and that quantity is the state of the SmoothDamp, as in it gets changed with each call to SmoothDamp,

You could either:

  • make an m_Velocity for each particle (eg an equivalently-sized array)

OR

  • as you loop over each particle, capture the m_Velocity in a local variable, pass that by ref into SmoothDamp, and when all particle have been itersted, copy that local variable’s value (which should have had only the LAST particle velocity updated to it) and put it back in m_Velocity… this might have other side effects but I imagine it might work.
1 Like

Could I get some code support?