Taking Control Over NavMesh Agent GameObject Temporarily

I am designing enemies for a game and it is a requirement that I move at least their colliders and model off of the navmesh briefly for a jumping attack. The character would jump into the air and then land again, where its NavMesh Agent would be re-enabled and it would continue pathfinding after landing on a viable NavMesh surface.

At the moment, I am disabling the NavMesh Agent and moving the character through code to its destination, where I re-enable the NavMesh Agent component. Occasionally, I have issues with the agent not being placed on a NavMesh surface. Am I going about this the right way by disabling the agent entirely? Or should I separate the model and colliders from the NavMesh agent? In general, what are viable ways to temporarily control the NavMesh agent’s object movement and then ensure that the agent is placed on a NavMesh when the component is re-enabled?

1 Like

You need to warp the agent to their new location after the end of the attack as you are re-enabling the Agent. I show how to do a jump attack in AI Series Part 21. That may help you understand it in more depth.

Yes, disabling the NavMesh Agent component is a proper way.

What you need to do is, when they are in air, i.e., when NavMesh Agent is disabled, do Raycast(…) down to check if they are grounded. You should enable the NavMesh Agent after they are grounded.

In addition, the ground check logic should be executed only after a “protectedJumpTime”, otherwise the agent will enable instantly after jumping which prevents a proper jump.

In a tech demo of my project I use the logic above:

you can check out the demo “NavMeshLinke/OffMeshLink Jump”.

Thank you both for the feedback. I have seen some of your other videos Chris, they have been very useful for this project.