/// <summary> /// Function to update the waypoint movement based on Dijkstra's Algorithm /// </summary> internal void waypointUpdate() { // Set to Debug values for testing if (InspectorDebugging && FinalTargetWaypointDebug != null) { FinalTargetWaypoint = FinalTargetWaypointDebug; } // If we still have some place to go... if (FinalTargetWaypoint != null) { // Update the next waypoint to go to // -- Update Timer waypointUpdateTimer += (float)TimeManager.GetDeltaTime(TimeManager.TimeType.Game); // -- Timer Check if (waypointUpdateTimer > WaypointUpdateDelay) { currentTargetWaypoint = WaypointMap.GetNearestWaypointToGoTo(currentWaypoint, FinalTargetWaypoint); // -- Reset Timer waypointUpdateTimer = 0.0f; } // Check if there is a path/Waypoint to go on if (currentTargetWaypoint != null) { // Check if we have reached the Waypoint if (reachedWaypoint(currentTargetWaypoint)) { // Update the current Waypoint currentWaypoint = WaypointMap.FindNearestWaypoint(transform.position); } else { // Get direction to the target Vector2 dir = currentTargetWaypoint.transform.position - transform.position; dir.Normalize(); // Head to the target transform.position += (Vector3)dir * Speed * (float)TimeManager.GetDeltaTime(TimeManager.TimeType.Game); // Update Rotation updateRotation(dir); } } else { // If there is no more path, we stop deciding to go there FinalTargetWaypoint = null; } } // Update the Debug Values if (InspectorDebugging) { FinalTargetWaypointDebug = FinalTargetWaypoint; } }