Search Unity

Is NavMeshAgent a RigidBody?

Discussion in 'Navigation' started by twda, May 7, 2017.

  1. twda

    twda

    Joined:
    Oct 25, 2012
    Posts:
    111
    I was using a RigidBody and a Collider on my model.
    If I didn't have the RigidBody, my model would float in the air.
    If I didn't have the Collider, my model would fall through the ground.

    Now I've detected that if I remove the RigidBody and Collider and just have a NavMeshAgent on the model, my model doesn't fall through the ground anymore and doesn't float in the air.

    That's why I was wondering if the NavMeshAgent is a RigidBody + Collider itself, and I should NOT add another RigidBody and Collider to my model in order to keep everything clean and simple.

    Thank you for any thoughts on this.
     
    Last edited: May 7, 2017
  2. twda

    twda

    Joined:
    Oct 25, 2012
    Posts:
    111
    Does nobody have an answer?
     
  3. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    Hi twda, the NavmeshAgent does not have a Rigidbody or Collider, you should add those components yourself if you want to use them. The NavMeshAgent, during its Update function will 'lock' the player to the NavMesh itself. This can have some unintended consequences if you are using a Rigidbody (and specifically FixedUpdate) to move the character, IE, it can produce stuttering when the Rigidbody and NavMeshAgent do not 'agree.'

    That being said, I'd have to know more about your setup, but the basic answer is that the NavMeshAgent doesn't inherently contain a Rigidbody/Collider.
     
  4. twda

    twda

    Joined:
    Oct 25, 2012
    Posts:
    111
    @Multithreaded_Games
    I think you're not correct.

    Create a hill-like terrain and create a NavMesh.
    Place some cubes with a box collider on it so that we can test collisions.

    Then create a Sphere.
    Add a Sphere Collider to it.
    Add a RigidBody to it.

    Place the sphere over the navmeshed terrain.

    The sphere will fall down to the ground, and if your terrain is an uneven hill, it will follow the hill's curvatures.

    Now to test my thesis, remove the Sphere Collider and remove the RigidBody.
    Add a NavMesh agent to the Sphere.

    It will behave just like before when we had a RigidBody and a SphereCollider on it.
    It won't fall from the sky to the terrain anymore, but it will immediately be grounded because it wants to follow the NavMeshAgent, but that doesn't contradict my thesis.

    That's why I thought a NavMeshAgent is a RigidBody + Collider itself.

    Perhaps one of the Unity devs can jump in here?
     
  5. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
  6. GamesOfArcadia

    GamesOfArcadia

    Joined:
    Dec 12, 2020
    Posts:
    2
    Hi there,

    just to add something that happened to me on the same topic.

    I have a level happening in a sphere wich is used as zone limit with an OnTriggerExit function.
    It worked verry well, until I've tried to jump. The way my jumps works, in case of big drop, it deactivate the navmesh agent of the player, set the rigidbody to non-kinematic with the gravity on, and proceed with the fall. But for some reason (haven't looked deeply into it yet), in that sphere level, when the jump deactivate the navmesh agent, the sphere see this as a trigger exit and act as written.
    So, or the navmesh agent is a rigidbody in someway (for what I know they are the one calling the collisions) or the switch from kinematic to non kinematic does it.

    Just a warm comment, might edit it later.

    [EDIT]

    Alright, so the switch from kinematic to non-kinematic trigger the OnTrigger function.
     
    Last edited: Aug 14, 2021