I’m making waypoints for my game, the AI is supposed to walk until the point, and when it’s close enough, wait a few seconds and walk to next one
the problem is that it walks to the first waypoint, and then it rotates and looks at the second and don´t move, no matter how many waypoints there is
here´s some code, it´s called in the Update Function
function movement()
{
var relativeVector= nextPosition - transform.position;
var desiredRotation= Quaternion.LookRotation(relativeVector);
turnStrenght = Mathf.Min(rotationSpeed*Time.deltaTime, 1);
transform.rotation = Quaternion.Slerp(transform.rotation, desiredRotation, turnStrenght);
var angleToTarget = Vector3.Angle(nextPosition, transform.forward);
if(angleToTarget < 50)
{
transform.Translate(0,0,velocidade*Time.deltaTime);
}
var distanceToDestination = Vector3.Distance(nextPosition, transform.position);
if(radiusToDestination > distanceToDestination)
{
yield goToNextWaypoint();
}
}
function goToNextWaypoint()
{
currentPoint ++;
print(currentPoint);
if(currentPoint > (patrolPoints.length - 1))
{
currentPoint = 0;
}
nextPosition = patrolPoints[currentPoint];
nextPosition.y = transform.position.y;
yield WaitForSeconds(2);
}
i tried adding a flag to the movement funtion so that it only works after the whole function is finished, but that didn´t work either
any ideas guys?
thanks in advance