Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Taking Control Over NavMesh Agent GameObject Temporarily

Discussion in 'Navigation' started by johnmanardiii, Mar 15, 2022.

  1. johnmanardiii

    johnmanardiii

    Joined:
    Nov 11, 2018
    Posts:
    7
    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?
     
  2. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    265
    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.
     
  3. JavaBob

    JavaBob

    Joined:
    Apr 24, 2018
    Posts:
    19
    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:
    https://blobcreate.itch.io/demos-for-projectile-toolkit
    you can check out the demo "NavMeshLinke/OffMeshLink Jump".
     
    Last edited: Apr 26, 2022
  4. johnmanardiii

    johnmanardiii

    Joined:
    Nov 11, 2018
    Posts:
    7
    Thank you both for the feedback. I have seen some of your other videos Chris, they have been very useful for this project.