void Patrol()
{
agent.speed = patrolSpeed;
if (Vector3.Distance(this.transform.position, waypoints[waypointInd].transform.position) >= 1)
{
Quaternion newRotation = Quaternion.LookRotation(waypoints[waypointInd].transform.position - this.transform.position);
//newRotation.x = 0f;
//newRotation.z = 0f;
//this.transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 5f);
agent.SetDestination(waypoints[waypointInd].transform.position);
}
else if (Vector3.Distance(this.transform.position, waypoints[waypointInd].transform.position) <= 1)
{
// if we're close to the position we want to get to
// then it is time to go the next position
waypointInd += 1;
if (waypointInd >= waypoints.Length)
{
waypointInd = 0;
}
}
}