I don’t know where to go next, I tried doing this with the script, but I’m kind of shooting in the dark here, might just have to set it on the backburner and come back to it when I have a little more experience to go on:
using System;
using UnityEngine;
namespace UnityStandardAssets.Characters.ThirdPerson
{
[RequireComponent(typeof (UnityEngine.AI.NavMeshAgent))]
[RequireComponent(typeof (ThirdPersonCharacter))]
public class AICharacterControl : MonoBehaviour
{
public UnityEngine.AI.NavMeshAgent agent { get; private set; } // the navmesh agent required for the path finding
public ThirdPersonCharacter character { get; private set; } // the character we are controlling
public Transform[] points;
private int destPoint = 0;
private Animator anim;
private void Start()
{
// get the components on the object we need ( should not be null due to require component so no need to check )
anim = GetComponent<Animator> ();
agent = GetComponentInChildren<UnityEngine.AI.NavMeshAgent>();
character = GetComponent<ThirdPersonCharacter>();
destPoint = UnityEngine.Random.Range (0, points.Length);
NextPoint ();
agent.updateRotation = false;
agent.updatePosition = true;
}
void NextPoint() {
if (points.Length == 0)
return;
destPoint = UnityEngine.Random.Range (0, points.Length);
agent.destination = points[destPoint].position;
destPoint = (destPoint + 1) % points.Length;
}
private void Update()
{
if (agent.isStopped) {
anim.SetFloat (“Speed_f”, 0);
return;
}
anim.SetFloat (“Speed_f”, 1f);
if (!agent.pathPending && agent.remainingDistance < 0.5f) {
NextPoint ();
}
}
void OnAnimatorMove()
{
agent.speed = (anim.deltaPosition / Time.deltaTime).magnitude;
}
}
}