So I have this script for making an AI wander to a random point within a given range.
It works as to so far that my enemy moves but it keeps spinning around itself while doing it.
void Update()
{
if (isWandering) {
WanderWaypoint ();
Wander ();
}
}
void WanderWaypoint()
{
float RandomizedXPos = Random.Range (transform.position.x - wanderRange, transform.position.x + wanderRange);
float RandomizedZPos = Random.Range (transform.position.z - wanderRange, transform.position.z + wanderRange);
wayPoint = new Vector3 (RandomizedXPos, 1, RandomizedZPos);
}
void Wander()
{
transform.LookAt (wayPoint);
transform.position += transform.TransformDirection (Vector3.forward) * walkSpeed * Time.deltaTime;
if ((transform.position - wayPoint).magnitude < 3) {
WanderWaypoint ();
}
}
Does Anybody see the problem?
Thanks in advance!