1

The resulting image So I have made a Navmesh surface on a plane in unity 3D. The cube will constantly spawn cylinders to get it to move towards the sphere. But the cylinders spawned continue to try to move on the edge of Navmesh surface and as a result, stuck.

I've tried to change the size of the plane but it didn't change anything. I think it might be something wrong with the spawning path but I don't know what it is.

These are the codes for the spawning.

public class EnemySpawner : MonoBehaviour
{
    public GameObject enemy;               
    public float SpawnTime = 2f;
    public Transform[] spawnPoints;


    void Start()
    {
        InvokeRepeating("Spawn", SpawnTime, SpawnTime);
    }

    void Spawn()
    {
        int spawnPointIndex = Random.Range(0, spawnPoints.Length);

        Instantiate(enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
    }
}

These are the codes for the Nav agent

public class EnemyController : MonoBehaviour
{
    public Transform player;
    private UnityEngine.AI.NavMeshAgent agent;

    // Start is called before the first frame update
    void Start()
    {
        agent = GetComponent<UnityEngine.AI.NavMeshAgent>();
    }

    // Update is called once per frame
    void Update()
    {
        agent.destination = player.position;
    }
}

I expect it to move directly towards the sphere, but it's actually trying to move along the edge of NavMesh surface.

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
YoKurt
  • 11
  • 1

0 Answers0