Search Unity

Navmeshagent thrown into endless rotation and backward motion when explosion effect near object.

Discussion in 'Navigation' started by kerrmedia, Jul 29, 2017.

  1. kerrmedia

    kerrmedia

    Joined:
    Nov 4, 2015
    Posts:
    250
    I have spider mesh that animates nicely around my scene using navmeshagent baked paths and targets.
    But I have added recently exploding crates, gameObjects that explode by setting off the standard assets explosion particle effect, which does include forces.
    If one explodes near the spider, it spins around the scene, then animates like its going forward, but its really endlessly rotating and sliding backwards. There are no targets where it ends up. Clearly the forces have effected the navmeshagent, but setting navmeshagent.isStopped to false does not seem to clear it up.
    Any help understanding what is going on here would be a big help. If in debug I disable the navmeshagent and re-enable it while the game is playing, the spider seems to clear up its problem and once again animate, following the navmesh path to the next target.
     
    Last edited: Jul 30, 2017
  2. kerrmedia

    kerrmedia

    Joined:
    Nov 4, 2015
    Posts:
    250
    checking "Is Kinematic" in the Rigidbody seemed to fix the effect of the explosions, but was that the right way to deal with this?
     
  3. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    Hey, "IsKinematic" controls wether forces/physics are applied to this rigidbody.

    That is why the navmeshagent is not effected by forces anymore. If you want to affect NavAgent with the explosion forces, you could deactivate the NavAgent (NavAgent.enabled = false) and apply the physics.

    Wait until the effect wears off (Rigidbody.IsSleeping) and then reactivate the NavAgent again. Make sure you use "NavMesh.SamplePosition" to bring the NavAgent back to navmesh, but be aware that the Agent "teleports" back to the next possible navmesh position if you do that. A better solution might be to make sure the explosion does not take him off the navmesh or let him die if this fits your gamedesign :).

    Another possiblity might be to play around with the physics material of the floor, to prevent sliding and endless rotation. I have tried this before, without success, but it might be possible, if you have a little more patience.
     
    Tset_Tsyung and kerrmedia like this.
  4. kerrmedia

    kerrmedia

    Joined:
    Nov 4, 2015
    Posts:
    250
    Perfect Dwin, thanks, that gives me the tool I need.
     
    Tset_Tsyung and DwinTeimlon like this.
  5. MikeTyke

    MikeTyke

    Joined:
    Dec 16, 2015
    Posts:
    2
    Thanks - my little guy was spinning in circles all over the place until I ticked the IsKinematic box
     
  6. y0_0go

    y0_0go

    Joined:
    Aug 17, 2022
    Posts:
    2
    Thanks a lot for this thread. My little guy was also spinning until I enabled IsKinematic.