One routine is influencing in other

Hi!

I have a problem with my this code and I am not understanding what is wrong:

private static IEnumerator routineDelay(MonoBehaviour mono, List<Transform> objects, float delay, Vector3 target, float speed)
{
    for (int i= 0; i < objects.Count;i++)
    {   
         Vector3 n;
         n += objects[i].localPosition;
         mono.StartCoroutine(routineSmooth(objects[i], n, speed));
         yield return new WaitForSeconds(delay);
    }
}

private static IEnumerator routineSmooth(Transform objToDamp, Vector3 target, float speed)
{
     velocity = new Vector3();
     while (!exit)
     {
           objToDamp.transform.position = Vector3.SmoothDamp(objToDamp.transform.position, target, ref velocity, 1, 20, speed * Time.deltaTime);
           yield return null;
     }
}

What is happens is that sounds like one routine is influencing in the others. Like some variable is referenced and not actually run as unique in each routine.

But I am creating the parameters like Velocity to a new each time to avoid it.

Any sugestion?

Thank you

Im not following where i comes from in

private static IEnumerator routineDelay(MonoBehaviour mono, List<Transform> objects, float delay, Vector3 target, float speed)
{
    Vector3 n;
    n += objects[i].localPosition;
    mono.StartCoroutine(routineSmooth(objects[i], n, speed));
    yield return new WaitForSeconds(delay);
}
1 Like

Sorry, the code was wrong. I correct it now.
Was missing a loop for…

The first call is from:
Twinning.doDampingChilds(this, objList, target, speed, delay);

1 Like

The idea is very simple. Just move objects to another position but with a delay between them so the animation look better.

If we call just one routine works fine.

Look, this is called just once Twinning.doDampingChilds(this, objList, target, speed, delay);
This “objList” have childrens that we wll pass each in “routineSmooth”

The problem is in this line:
velocity = new Vector3();

I really did a mess here…I have declared as Static…

that will do it