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();
}
}