In my scene, I have an agent which moves to a specific destination. As soon I try to duplicate it in order to create a second agent the resulting behavior is quite strange: the agents get transported to opposite corners of the map and stop moving. Also, the navigation mesh at runtime seems altered (as you can see in the second screenshot). As soon I disable one agent the other start working as expected.
EDIT: This is the code I'm using for the character (as you can see I manage the character rotation/translation manually instead of delegating the agent, which works well till I assign the same script to a second character as mentioned before).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class AI_PlayerController : MonoBehaviour
{
public Transform goal;
bool isTracking = false;
public float speed = 1.0f;
Vector3 currentDirection;
Animator anim;
NavMeshAgent agent;
Vector2 smoothDeltaPosition = Vector2.zero;
Vector2 velocity = Vector2.zero;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
agent = GetComponent<NavMeshAgent>();
agent.SetDestination(goal.position);
agent.updatePosition = false;
agent.updateRotation = false;
}
void Update ()
{
if (agent.remainingDistance > agent.radius) {
Vector3 worldDeltaPosition = agent.nextPosition - transform.position;
worldDeltaPosition.y = 0;
Quaternion rotation = Quaternion.LookRotation(worldDeltaPosition);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, .1f);
anim.SetBool("move", true);
} else {
anim.SetBool("move", false);
}
}
void OnAnimatorMove ()
{
// Update position to agent position
transform.position = agent.nextPosition;
}
}