Pathfinding in a constant circle

So I have been going through the tutorials here and I have a, I think, very simple question. Instead of having the AI pick from the radius around the NPC/Character I am wanting to put a gameobject down and just have the radius around it. So how would I change the following code to accomplish it? Thanks in advance.

using UnityEngine;
using System.Collections;
using Pathfinding;
using UnityStandardAssets.Characters.ThirdPerson;
public class Wander : MonoBehaviour
{
    public float radius = 20;    
    IAstarAI ai;
    public ThirdPersonCharacter character;
    private Animator anim;
    void Start()
    {
        anim = GetComponent<Animator>();  //Get this NPCs Animator
        ai = GetComponent<IAstarAI>();
        if (ai != null) ai.onSearchPath += Update;
    }
    Vector3 PickRandomPoint()
    {
        var point = Random.insideUnitSphere * radius;
        point.y = 0;
        point += ai.position;
        return point;
    }
    void Update()
    {
        // Update the destination of the AI if
        // the AI is not already calculating a path and
        // the ai has reached the end of the path or it has no path at all
        if (!ai.pathPending && (ai.reachedEndOfPath || !ai.hasPath))
        {
            ai.destination = PickRandomPoint();
            ai.SearchPath();
        }
    }
    void OnCollisionEnter(Collision collision)
    {
        ai.destination = PickRandomPoint();
        ai.SearchPath();
    }
}

Ok I found what I was looking for. And for anyone else looking for this adding an original start vector and adding it with this code fixes it. Thanks

var point = Random.insideUnitSphere * radius;  //Make a random Vector Number
                point.y = 0;  //Set the Y coordinate to 0 to stay on same level
                endPoint = point + startPoint;  //Add the new Random Vector to the original location in center of sphere.
                gameObject.transform.position = endPoint;   //Set position of Cube to new random spot.
1 Like