I have an issue with the tank character. The Unity's navmesh agent only has a cylinder shape, so when the enemies are nearby, it causes unwanted results. If the navmesh is too big(to cover the entire tank body), the enemies can't approach the side of the vehicle. If the navmesh is too small(only covering the center), the enemies pass through the front of the car and back. Putting the collider doesn't make any changes, the unity's navmesh agent ignores whether it has a collider. How do I make navmeshagent shape fit the mesh?
-
2\$\begingroup\$ I don't think this is possible with the Unity nav mesh system. The cylindrical agent shapes are pretty ingrained in it. You might have to use a 3rd party solution (no, I don't know one) or roll your own. \$\endgroup\$– PhilippJun 14 at 8:14
-
2\$\begingroup\$ Unity is using reciprocal velocity obstacles (RVO) to predict and prevent collisions.. RVO is an obstacle avoidance algorithm based on circular agents, so this is not possible. \$\endgroup\$– MangataJun 14 at 10:00
1 Answer
You can try:
Modify the NavMeshAgent's radius: The NavMeshAgent has a "Radius" property that determines the size of the agent's navigation cylinder. You can adjust this value to better match the size of your tank mesh. Increase the radius if the enemies need to approach the tank from the sides, or decrease it if you want more precise collision detection.
Use multiple NavMeshAgent components: Instead of relying on a single NavMeshAgent for the entire tank, you can attach multiple smaller NavMeshAgent components to different parts of the tank, such as the front, sides, and back. This way, each agent can have a smaller radius and navigate more accurately around the tank's specific shape.
Employ additional colliders: While the NavMeshAgent doesn't directly interact with colliders, you can add separate colliders to the tank, such as box colliders or mesh colliders, that cover the entire tank's body. These colliders can be used to detect collisions with enemies and trigger appropriate actions or behaviors.
Combine navigation with custom steering behaviors: Instead of relying solely on the NavMeshAgent for enemy movement, you can combine it with custom steering behaviors, such as obstacle avoidance or path following. By implementing these behaviors, you can provide more precise control over enemy movement around the tank and ensure they navigate according to your desired rules.