#Help with navmeshagent early stopping
1 messages · Page 1 of 1 (latest)
I'm trying to code so enemies chase the player on a navmesh and stop when they are in front of the player's vision instead of moving to the side or behind the player
void Update()
{
Vector3 viewDirection = player.transform.position;
viewDirection.y = transform.position.y;
transform.LookAt(viewDirection);
GetComponent<NavMeshAgent>().SetDestination(player.transform.position);
}
Created a thread @latent scaffold because there was another problem going on aswell
The issue you seem to be having is that they are trying move to the exact position of the player do you have a collider on your player?
Also, is the code linked in an update of any sort?
it does not collide with the enemies
its in an update
Are you sure? it looks like the enemies are colliding with something
You should be able to see this in the scene view
In any case, this could be solved by checking the distance between the player and the enemy, and if it is below a certain threshold, stop the agent from moving and dont give it a new destination.
I can walk right through them
I think the navmesh agent automatically evades other agents
Not super sure about that one though
Try the above, report your results
If you need any help, ping me in this thread and we'll take another look :)
stopping distance is really weird
like its suppose to stop at a certain distance
but sometimes it just doesnt
I think that is part of the problem
its ignoring that and going into the player
1 isnt super far away, have you tried higher values?
thank you for help. I dont even know what the problem is anymore so I may just try again later