Why when using waypoints when starting the game the moving object is jumping a bit forward ?

I mean by jumping that the moving object between the waypoints is changing position like jumping to another position it’s very quick and small change but you can see it.

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

public class Waypoints : MonoBehaviour
{
    public GameObject[] waypoints;
    public int num = 0;

    public float minDist;
    public float speed;

    public bool rand = false;
    public bool go = true;
   
    // Update is called once per frame
    void Update()
    {
        float dist = Vector3.Distance(gameObject.transform.position, waypoints[num].transform.position);
        if (go)
        {
            if (dist > minDist)
            {
                Move();
            }
            else
            {
                if (!rand)
                {
                    if (num + 1 == waypoints.Length)
                    {
                        num = 0;
                    }
                    else
                    {
                        num++;
                    }
                }
                else 
                {
                    num = Random.Range(0, waypoints.Length);
                }
            }

        }
    }

    public void Move()
    {
        transform.LookAt(waypoints[num].transform.position);
        transform.position += gameObject.transform.forward * speed * Time.deltaTime;
    }
}

I recorded a very short video clip showing the problem what I mean by jumping position:

I found now that if I start the game when the bool variable ‘go’ is false and then when the game started I’m changing ‘go’ to true it’s working fine. The problem is when I’m starting the game and ‘go’ is set to true. Can’t figure out why.

A lot of times when starting the game the initial frames are not smooth.
They maybe much longer than after everything is loaded into memory.

You are better waiting a bit before starting your movement.
This could be worse in the editor compared to a build.

You can see this looking at the profiler or logging the time.deltatime

It’s true, I’ve seen this myself and talk about it on the forums. As I recall, it’s the very beginning and only in the editor.

So, as your tests showed that things were okay when you changed the bool after loading (which is good to test), I believe you can safely accept that as some editor lag and it would not affect a build. You can always test that to be sure, if you want.

1 Like

Right I just tested it now and it’s working fine after building.

Thank you.