After loading NavMesh agent doesn't move



  • Hello,

    I've been at this for a couple days and I'm not a very experienced when it comes to getting the objects to move.  I replaced the pointer object with my FPS so that the enemy will move toward my fps while I move around the map within the baked NavMesh...

    for the life of me I can't get the enemies to move.

    Please Help.

    Just and example code with how I can implement this with just moving an object on the screen that replaces the pointer game object component would help out a lot.



  • Hello,

    moving a NavMesh Agent is described well on the official Unity documentation, where you can find several examples too.

    I would suggest looking at this page for a basic start:
    https://docs.unity3d.com/Manual/nav-MoveToDestination.html

    Note that setting the destination variable on a NavMesh Agent is not something specific to our asset - that's default Unity functionality.



  • I got it to follow but the fps...  problem now is the portal doesn't work.

    If I add the agent.Warp(path[I]; the agent's don't move they will seek but not move to the players location.

    here is my code:

    using UnityEngine;
    using UnityEngine.AI;
    using System.Collections;

    namespace NavMeshExtension
    {
        /// <summary>
        /// Example integration of NavMesh Agents with portal behavior.
        /// <summary>
        [RequireComponent(typeof(NavMeshAgent))]
        public class AgentController : MonoBehaviour
        {
            /// <summary>
            /// Target destination object, set by mouse input.
            /// <summary>
            Transform player;
            public Animator controller;
            //reference to agent
            private NavMeshAgent agent;
            //resulting path from the PortalManager call
            private Vector3[] path;

    //get components
            void Start()
            {
                agent = GetComponent<NavMeshAgent>();
                player = GameObject.FindGameObjectWithTag("Player").transform;
               
                agent.Warp(this.transform.position);
               
            }

    void Update()
            {
     
                        path = PortalManager.GetPath(transform.position, player.transform.position);

    StopAllCoroutines();
         
                        StartCoroutine(GoToDestination());
               
            }

    IEnumerator GoToDestination()
            {
         
                int i = 0;

    while(i < path.Length)
                {
                       
                    agent.Warp(path'['I']');  <--------------------If you comment this out the robot & my agent will follow but not teleport had to add the '' to show the brackets... Any ideas?
                    i++;

    agent.SetDestination(path'['i']');
                    while (agent.pathPending)
                        yield return null;

    float remain = agent.remainingDistance;
                    while (remain == Mathf.Infinity || remain - agent.stoppingDistance > float.Epsilon
                    || agent.pathStatus != NavMeshPathStatus.PathComplete)
                    {
                        remain = agent.remainingDistance;
                        yield return null;
                    }

    i++;
                }

    //agent reached the final destination
                #if UNITY_4_6 || UNITY_4_7
                agent.Stop(true);
                #elif UNITY_5_6_OR_NEWER
        agent.isStopped = true;
        #else
        agent.Stop();
                #endif
            }
        }
    }


Log in to reply