Home > Software design >  Unity navMeshAgent not working on terrain
Unity navMeshAgent not working on terrain

Time:04-30

The Unity Navmeshagent is not working !on terrain!. I'm very kinda new to unity and need help with the navmesh agent.

It's baking fine just that the entity or slender man is not moving. It's actually in the inspector but it's only like 0.0001 per second. Bake and navmesh agent settings are the photos.

Script:

using UnityEngine;
using UnityEngine.AI;

public class enemymovement : MonoBehaviour
{
    private NavMeshAgent nma;
    public Transform player;
    private void Awake()
    {
        nma = GetComponent<NavMeshAgent>();
        StartCoroutine("followpath");
    }

    private IEnumerator followpath()
    {
        while (true)
        {
            nma.SetDestination(player.position);
            yield return new WaitForSeconds(0.1f);
        }
    }
}

CodePudding user response:

You need to use nma.SetDestination(player.position)

And dont put this in an update because it means that your agent will try to calculate a new path EVERY frame. I suggest using a Coroutine that will call SetDestination from time to time instead of every frame.

  • Related