Search Unity

Using navmesh with ragdoll

Discussion in 'Navigation' started by witcher101, May 4, 2018.

  1. witcher101

    witcher101

    Joined:
    Sep 9, 2015
    Posts:
    516
    When i add a explosion force to my Aienemy and make it ragdoll. My Ai and navagent ends up in different position. This causes a teleportaion of my enemy when it resumes AI after end of ragdoll. There also seems to be a lot of jitter. Any1 knows how to workaround this.
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    In my game I'm using NavMeshAgent on an object that has a Rigidbody. I'm only using the NavMeshAgent to get a valid path, so the agent doesn't change the position of the game object. Any time the agent goes off the NavMesh (for example, stops being grounded) I disable the NavMeshAgent, and re-enable it when it lands. So in your case, I think you'd just want to disable the NavMeshAgent at times when you don't want it affecting your object.

    Note: The NavMeshAgent documentation specifically warns about letting both a Rigidbody and a NavMeshAgent control the location of an object. It's either-or.
     
  3. newjerseyrunner

    newjerseyrunner

    Joined:
    Jul 20, 2017
    Posts:
    966
    I also turn the navmeshagent off when it's hit with a force. Can you check on the forces on your character and turn the navmeshagent on and off based on a threshold?
     
  4. witcher101

    witcher101

    Joined:
    Sep 9, 2015
    Posts:
    516
    I tried this it works sometimes but sometimes my char gets stretched
     
  5. newjerseyrunner

    newjerseyrunner

    Joined:
    Jul 20, 2017
    Posts:
    966
    Are your navmeshagent and physics body on the same object or do you have subobjects? Please let me know if I correctly understand the problem:

    You have a gameobject that is navigating on a navmesh.
    That gameobject then encounters something that causes it's ragdoll (which is a subobject) to become active.
    This allows the ragdoll to fall or be moved by forces.
    But this does not affect your root object which the navmeshagent is actually attached to.

    Is this what is happening? The reason this is happening is because the physics is allowing the objects to move freely, but they are still subobjects of something else, so their position is still relative to that. So if a force pushes your a subobject ten units from the main object, the main object is still transform.position. You'll have to recenter your root object after the physics simulation is over with.