I’m working on a patrolling enemy that uses the NavMesh pathfinding to get from point a to point b and back again(I have empties acting as the points, the empties have trigger colliders on them that switch the point the enemy is navigating to when it gets there). I’m running into the issue of… well I don’t really know how to describe it. I guess if I had to put it into words, it’s like the enemy is just learning how to walk, it’ s really bizarre.
Why dont you define points where your AI should go and instead of using a “Collider” you work with the NavMesh API,
use the distance to destination to decide when the AI should walk back etc.
Colliders are not really used for that since they can cause many issues
That’s what tried originally but the enemy just walked until they hit the point and then vibrated for several seconds, never moving to the next point.
Then your logic ofc. is not right
If you want to make pair programming, would love to help you out: TDS-Studio
Ensure to have a mic and AnyDesk
I’m not interested in a discord call, sorry. Here’s my new logic(pulled from a forum & modified)
private void Update()
{
if (!agent.pathPending)
{
if (agent.remainingDistance <= agent.stoppingDistance)
{
if (!agent.hasPath || agent.velocity.sqrMagnitude == 0f)
{
if (WP == WP2.position)
{
WP = WP1.position;
Debug.Log("Here");
}
else if (WP == WP1.position)
{
WP = WP2.position;
Debug.Log("There");
}
}
}
}
agent.SetDestination(WP);
}
It works fine twice, the agent goes to the first, point, then the second, then back to the first, then it breaks and vibrates at the point again…? I’m sure my logic is wrong here but I don’t know why.
Thats your problem:
if (WP == WP2.position)
{
WP = WP1.position;
Debug.Log("Here");
}
else if (WP == WP1.position)
{
WP = WP2.position;
Debug.Log("There");
}
i dont know what “WP” is but
if (agent.remainingDistance <= agent.stoppingDistance)
Should be enough
Small edit :
if (!agent.hasPath
Should be used in a different context, if you assign a new destination, you have to check if he have a path, if so → move and calculate remaining path