Hello,
I’m currently working on Unity 3.5 and using the new NavMeshAgent stuff and loving it. I just have one issue. I have a sphere chasing the player and when it gets to a certain distance of the player, I have the sphere stop in it’s place. When the player gets out of range again, the sphere will chase the player again. I want the sphere to circle around the player when it is within distance. Below is some code.
using UnityEngine;
using System.Collections;
public class Surround : MonoBehaviour {
public Transform m_player;
private NavMeshAgent AI;
public Transform sphere;
// Use this for initialization
void Start () {
AI = GetComponent<NavMeshAgent>();
AI.SetDestination(m_player.position);
}
// Update is called once per frame
void Update () {
AI.destination = m_player.position;
sphere.LookAt(m_player);
AI.speed = 5;
if (AI.remainingDistance <= AI.stoppingDistance) {
Ai.speed = 0;
}
}
void OnTriggerEnter() {
Destroy(sphere.gameObject);
}
}
Thanks!