MoveTowards going too fast

Hi. I’m trying to create a cool camera panning overview of a level before you start playing it.

I have two scripts on my camera:

  • CameraManager, which controls the camera while you’re playing the level, and
  • CameraPan, which runs at the start of the level, disabling CameraManager until it’s done, then it deletes itself. CameraPan just teleports through all the waypoints so fast it’s finished before I even see it.

CameraPan.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraPan : MonoBehaviour
{
    public Vector3[] waypointPos;
    public Vector3[] waypointDir;
    public float[] waypointSpeed;

    // Start is called before the first frame update
    void Start()
    {
        GetComponent<CameraManager>().enabled = false;
    }

    // Update is called once per frame
    void Update()
    {
        if (GameObject.Find("Music").GetComponent<Music>().isHub == false)
        {
            transform.position = waypointPos[0];
            transform.eulerAngles = waypointDir[0];
            for (int i = 1; i > waypointDir.Length; i++)
            {
                transform.position = Vector3.MoveTowards(transform.position, waypointPos[i], waypointSpeed[i] * Time.deltaTime);
                transform.eulerAngles = Vector3.RotateTowards(transform.eulerAngles, waypointDir[i], waypointSpeed[i] * Time.deltaTime, 0);
            }
        }
        GetComponent<CameraManager>().enabled = true;
        Destroy(this);
    }
}

Dear Brother you can divide it by 2 or more something like this:

transform.position = Vector3.MoveTowards(
    transform.position,
    waypointPos[i],
    waypointSpeed[i] * Time.deltaTime / 3
);

I have divided by 3 you can do more.

Nevermind, I just had the wrong operator in the for loop, I should’ve had < in it. :blush: