EnemyMover Path Refactor causing 1 second delay on each path tile

Changing the Gameobject waypoints to Gameobject parent along with the Path tag switches from the child Path Tiles to the Parent tiles gameobject has caused a movement glitch I cannot figure out.

Every time the Ram moves between tiles, it pauses for one second, then continues its movement to the next tile. I have not made any changes to the LERP. And when I revert back to the original waypoints array loop with tagged child tiles, this works fine.

Am I missing something in my implementation of the parent object iteration?

 GameObject parent = GameObject.FindGameObjectWithTag("Path");

        foreach(Transform child in parent.transform)
        {
            Waypoint waypoint = child.GetComponent<Waypoint>();
            if(waypoint != null)
            {
                path.Add(waypoint);
            }
           path.Add(child.GetComponent<Waypoint>());
        }


The parent Path gameobject is tagged with Path. The children Tile gameobjects have their tags removed.

You are adding each waypoint twice. So, the ram gets to the waypoint, then need to go to the same position, then move to the next one

Well clearly I need to stop staring at the screen. Reading through that over and over again I never would have caught that.

You are exactly correct. Thank you so much for you reply and break down in the comments! Appreciate you!

It is a common problem to miss the forest for the trees. That happens even to experienced programmers. :wink:

If one cannot find the issue in the code, a common approach is to check the values. In this particular case, you could have logged the elements of path into your console with a for-loop.

Alternatively, if you use Visual Studio (not Visual Studio Code), you could simply set a breakpoint and inspect path. Using the debugger was not covered in this course but I wanted to mention it here anyway in case you’d like to test that. :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms