Set big object as NavMesh target

I have enemies moved by NavMesh Agent. The target is a static cylinder of scale x:3, y:1, z:3.
The problem is that ALL enemies are moving to THE SAME specific point of the cylinder edge, not the one that is closest to their actual position. It can happen that they walk around the cylinder to reach that point, instead stopping as soon as they reach the cylinder.

How can I move them to their nearest point on the cylinder edge?

Thank you in advance.

They move to the closest point to the target, not to the closest point to themselves. Instead of setting the target as

targetObject.transform.position

you could use

targetObject.transform.position + (targetObject.transform.position-gameObject.transform.position).normalized*1.5f

That way they will try to go to a point on a line between the start and the target, 1.5 meters away from the target position (should be the nearest edge). Maybe you have to switch the first + with a -, I haven’t tried it.

Well, you could do it this way…

Vector3 theSpotWeWant = theTarget.transform.position + (Vector3.Distance(myPos, theTarget.transform.position).normalized * theTargetCollider.radius);

Basically…

  1. Find the position of the thing you want to go to
  2. Get the direction to it with Vector3.Distance().normalized
  3. Multiply by the collider radius of the thing you’re moving toward.

That will give you the point between the Agent and the Target Cylinder on the edge of its collider… Not sure how useful or practical this is in practice, but it might sort out your issue.