Hi,
I’m using the AI Third Person Character include in the Standard Assets. I am using the character as the enemy for the Standard Asset FPS Character which is currently working fine. The error I get is
-
GetRemainingDistance" can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.NavMeshAgent:get_remainingDistance() -
SetDestination" can only be called on an active agent that has been placed on a NavMesh.
UnityEngine.NavMeshAgent:SetDestination(Vector3)
I will attach the script used by this AI character. Pls take a look a it and give me your suggestions.
using System;
using UnityEngine;
using System.Collections;
namespace UnityStandardAssets.Characters.ThirdPerson
{
[RequireComponent(typeof(NavMeshAgent))]
[RequireComponent(typeof(ThirdPersonCharacter))]
public class AICharacterControl : MonoBehaviour
{
public 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 target; // target to aim for
private void Start()
{
// get the components on the object we need ( should not be null due to require component so no need to check )
agent = GetComponentInChildren<NavMeshAgent>();
character = GetComponent<ThirdPersonCharacter>();
agent.updateRotation = false;
agent.updatePosition = true;
}
private void Update()
{
if (target != null)
agent.SetDestination(target.position);
if (agent.remainingDistance > agent.stoppingDistance)
character.Move(agent.desiredVelocity, false, false);
else
character.Move(Vector3.zero, false, false);
}
public void SetTarget(Transform target)
{
this.target = target;
}
}
}
Cheers,
Aadarsh…