NavMeshAgent not going to assigned target

Hi!

I’m making a scene to train a ML-Agent. It’s this 9 isolated isles:

Each isle is a copy of a prefab I made with terrain, navmesh and 2 agents: a deer and a hunter.

The hunter from the original isle (the one I dragged to create the prefab) is correctly chasing the deer. The problem is: hunters from the cloned isles are trying to chase the deer from the original isle, walking towards their respective isles edges.

I’m using a serialize field to determine each hunter goal, and each of these fields are correctly assigned with the deer from its own isle. This is my simple script for the hunters:

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

public class Chegar : MonoBehaviour
{
    [SerializeField] private Transform goalTransform;
    NavMeshAgent agent;

    void Start()
    {
        agent = GetComponent <NavMeshAgent>();
    }

    void Update()
    {
        agent.SetDestination(goalTransform.localPosition);
    }
}

Thanks in advance!

Visualization:

You are passing-in “localPosition”, you should use “transform.position” (world pos) to the NavMeshAgent.

It probably “appears” to work for your original agent because your “goalTransform” parent may be on 0,0,0 xD

1 Like

Thanks, man! Really appreciate the help.

But why localPos does not work?

1 Like

Local Space and World Space in Unity | by Marcus Ansley | Medium

1 Like