- Home /
Disable and Enable NavMesh Agent Unable to Move to Destination
Hi,
I'm trying to develop a 3D platformer. One of the powerups allows the user to sit back while a NavMesh Agent takes them up a few platforms.
If I start the NavMesh Agent in the scene and allow it to move to it's goal destination, it does so perfectly. However, if I only instantiate (or even enable it if it's already instantiated) during gameplay (as opposed to the beginning), it does not move to its goal destination.
Further, if it is going from the beginning and I disable and reenable it, it also does not work correctly and does not move to its goal destination.
Here is the code to get it to move to its goal destination:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using UnityEngine.AI;
using UnityStandardAssets.Characters.ThirdPerson;
public class MoveTo : MonoBehaviour {
public ThirdPersonCharacter character;
NavMeshAgent agent;
public indexFinder[] platforms;
void Start () {
platforms = FindObjectsOfType<indexFinder>().OrderBy( go => go.name ).ToArray();
agent = GetComponent<NavMeshAgent>();
agent.destination = platforms[platforms.Length-1].transform.position;
Debug.Log (agent.destination);
agent.updateRotation = false;
}
void Update(){
if (agent.remainingDistance > agent.stoppingDistance) {
character.Move (agent.desiredVelocity, false, true);
} else {
character.Move (Vector3.zero, false, false);
}
}
}
Any help would be hugely appreciated. Thanks
I'm now able to activate it. However, I have realised that the problem lies in trying to set the position/rotation of the agent before activation.
I have used Warp() as well as setting the transform directly. Neither have worked.
I've also tried a combination of disabling the Agent, setting the transform, enabling the agent, enabling the $$anonymous$$oveTo script.
Nothing worked correctly
Answer by RohanP · Feb 01, 2021 at 07:25 PM
Even i have the same issue.If anyone finds a fix please inform.
Your answer
Follow this Question
Related Questions
Failed to create agent because it is not close enough to the NavMesh 0 Answers
How to prevent NavMeshAgents from colliding when warped to same position? 0 Answers
Making NavMesh areas? 0 Answers
Is it possible to store NavMeshAgents paths and assign them to other NavMeshAgents later? 1 Answer
"SetDestination" can only be called on an active agent that has been placed on a NavMesh. 0 Answers