July 19, 2019
Updating Waypoint System
Starting with a base waypoint system I created with the Brackeys tower defense tutorial, I wanted to update it so that the overall path could be altered at run time. Basically, I didn’t want objects traveling along the waypoints to travel the full length everytime. I needed them to sometimes travel part way, sometimes more/less, sometimes the full way.
I decided I would have the main script holding the general waypoint information to hold the value for where objects should stop traveling. This way all objects could reference this for how far they should travel, and I could have anything else just change this single value to update where everything is going. This was as simple as adding an int value called currentEnd to this main script, Waypoints. Then I added the methods GetCurrentEnd (to return currentEnd) and SetCurrentEnd (to change the currentEnd value).
Next was updating the Waypoint_Movement script, which is attached to the objects moving along the waypoints to tell them how/where to move along the waypoints. They were originally moving from waypoint to waypoint until they reached the end of the Waypoints array (Waypoints.points.length – 1, the length of the waypoints array minus 1). This causes them to travel until they hit the end of the array. This was simply changed to check for [Waypoints.GetCurrentEnd() – 1] so they would only move to a waypoint determined by the currentEnd value at the time.
Finally, other scripts were able to add in the SetCurrentEnd() method call from Waypoints to their current functionality to have it basically update the length of the waypoint path further objects would travel.