The second problem encountered here was that the enemies would only count up to 2 waypoints, the first one they spawn at and the first one they move to. Now this wasn't a problem for The Grunt's as they had a single path and didn't require any more waypoints. However The Hunter's had a more complex path to take and so required more waypoints to guide them along so this was something that was imperative to fix for The Hunter's to function properly.
To fix this I created a float values to encompass pathPoint, pathProgress and pathLength. These values only ranged between 0 - 1.
When a numbered value has ++ written after it it's shorthand for "+ 1"
Basically what was wrong was that the script wasn't counting up the currentWaypoint value.
So when the enemies reached currentWaypoint value 1 (as lists always start with 0 and proceed up from there, basically meaning number 1 is the second thing in the list), the value wasn't being increased by 1 like it should have with ++ to allow the enemies to find the Transform of the Waypoint in element 2 in the list (2 being the 3rd item in the list).
So, using the pathPoint, pathProgress and pathLength values in an if statement before I was making the calculations to increase the currentWaypoint value I check if the gameObject this script is attached to (the enemy itself) has reached the endPosition Transform (endPosition is set to the Transform of the currentWaypoint), and the pathPoint value has gone above 1, then run our original calculations to move up he list of Waypoints to allow the enemies to move past just 2 Waypoints.
Figure 1. |
Figure 1. here just showcases that The Hunter's could now move along complex paths after this fix.
No comments:
Post a Comment