- Home /
My Nav Mesh Agent won't touch its target.
Basically I have a constantly updating target that the Agent is supposed to touch to trigger a game over screen. The Agent will get about .25m away from the target and won't get any closer. If I move the target the Agent moves until it is .25m away and doesn't try to touch it. What am I doing wrong?
Agent code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class AntagonistChase : MonoBehaviour
{
public NavMeshAgent agent;
[SerializeField] Transform Hero;
// Update is called once per frame
void Update()
{
agent.SetDestination(Hero.position);
}
}
Answer by Sacaitha · Apr 27 at 09:13 PM
Have you tried altering the Obstacle Avoidance values? What if the Agent is interpreting the hero as an obstacle?
Alternatively you can just ask him kindly
The Navmesh itself discludes the hero's separate layer from the mesh bake, and the hero can be anywhere (on the mesh) and still not touch the antagonist. The only way I can trigger the game over I have set up is by manually running into the antagonist, which is something (probably) none of my players will want to do.
I will consider asking him kindly. He is the antagonist so I don't think it will work.
Answer by nateK06 · Apr 27 at 08:52 PM
This is a terrible fix but I got it to work by changing the box collider on the Agent to be twice as wide so it would touch the target before it stopped. If anyone else finds a better fix please post it.
Your answer
Follow this Question
Related Questions
NavMeshAgent CalculatePath not working as expected 1 Answer
Reasons an NavMesh Agent.isStopped might be set to True? 0 Answers
NavMeshAgents with same variables acting differently 1 Answer
Making NavMesh areas? 0 Answers
"SetDestination" can only be called on an active agent that has been placed on a NavMesh. 0 Answers