Hey people, hope you’re well!
So I have a patrol path with various waypoints and a guard following that path. when the guard see the player he wanders over to the last location the player was in view. if the player ducks out of LOS then the guard investigates that position and if he finds nothing he continues his patrol at the last waypointIndex.
However I’d like the guard to just patrol from the closest waypoint from the investigation location.
At the moment I have a transform array of the waypoints and I guess I’d like to measure the distance to these waypoints when he enters the patrol state again and get the lowest float distance and then update the waypointIndex. at the moment I have this.
void CalculateClosestWaypoint()
{
foreach (Transform waypointPosition in waypoints)
{
float distanceToClosestWaypoint = Vector3.Distance(waypointPosition.position,
transform.position);
}
}
Just stuck on where to go from there. if there’s a more elegant solution please let me know and thanks so much for your time!!