public Vector3 Wander() { // change the wanderRotation value by a random amount // this keeps us walking in generally the same direction from frame to frame wanderRotation += Random.Range(-wanderRate, wanderRate); // start at our future position Vector3 future = FuturePosition(3f); // construct a unitRotation vector from our wanderRotation Vector3 unitRotation = VectorHelper.AngleToUnit(wanderRotation); // the wander position is our future position, plus a vector of magnitude wanderRadius pointing in the direction of our unitRotation Vector3 finalWanderPosition = future + (unitRotation * wanderRadius); // make sure it's drawn at the same level as our character finalWanderPosition.y = transform.position.y; if (wanderTarget) { // put it in position wanderTarget.transform.position = finalWanderPosition; } // seek the result return(Seek(finalWanderPosition)); }