GameObject move to each Vector3s in a list

Hey :slight_smile:

I’m trying to get a gameObject to move to a start position then move through a list of Vector3s before reaching the end of a path. I’ve got the start and end positions working well, however, I do not know how to get a gameObject to move through the Vector3 list INORDER. I’ve tried getting the positionList to convert to a position, however, nothing seems to be working and I’m not sure how to write a sequence to move to each individual point.
This is the code I’m working with;

  •  if (!startPositionIsSet && middlePossitionListIsSet && endPositionIsSet && Mathf.Approximately(gameObject.transform.position.magnitude, startPoint.magnitude))*
    
  •  {*
    
  •  	for (int i = 0; i < positionList.Count; i++)*
    
  •  	{*
    

gameObject.transform.position = Vector3.Lerp(gameObject.transform.position, positionList_, 1 / (duration * (Vector3.Distance(gameObject.transform.position, positionList*))));
Debug.Log("I am at " + transform.position + " Moving to position " + positionList);*_

hi;

u should use Coroutine for this I write the code for u ;

just put the vector3 in the inspector and set the object that u want to move between positions;

    public Vector3[] positions;
    public Transform ObjectToMove;
    public float MoveSpeed = 8;
    Coroutine MoveIE;

    void Start()
    {
        StartCoroutine(moveObject());

    }

    IEnumerator moveObject()
    {
        for (int i = 0; i < positions.Length; i++)
        {
            MoveIE = StartCoroutine(Moving(i));
            yield return MoveIE;
        }
    }

    IEnumerator Moving(int currentPosition)
    {
        while (ObjectToMove.transform.position != positions[currentPosition])
        {
            ObjectToMove.transform.position = Vector3.MoveTowards(ObjectToMove.transform.position, positions[currentPosition] , MoveSpeed * Time.deltaTime);
            yield return null;
        }
 
    }