Search Unity

Navmesh and Rigidbody Causing Camera Jitter

Discussion in 'Navigation' started by coute, Feb 4, 2018.

  1. coute

    coute

    Joined:
    Jul 26, 2014
    Posts:
    9
    So my game's player is controlled by input keys and changing the velocity on its rigidbody and all the other NPCs are controlled by navmesh. I noticed that when a NPC chases the player, it will jitter around when the camera moves with the player.

    I read up on this and I know it happens because of a Update/Fixed Update/Late Update issue. I use Pro 2d Camera and when I changed it from Fixed Update to Late Update, the enemies stopped jittering but instead, the player started doing it. I've tried moving the SetDestination of the NPCs in different Update/Fixed Update/Late Update functions and same with the player's rigidbody velocity change but that's not working.

    How can I fix the jitter for both the NPCs and the Player? Some answers recommend changing something with the camera but I don't understand those answers at all, I didn't write the camera so I have no idea how to edit its code.
     
  2. SM_AF

    SM_AF

    Joined:
    Aug 1, 2017
    Posts:
    23
    I reported this bug to Unity recently. It's basically about the same thing. They need to update the agent's position in FixedUpdate if the physics interactions between non-kinematic rigidbodies and the agent who has a kinematic rigidbody are supposed to work well. Fixing this bug should solve your issue as well :D

    Well... for you, there might be some other options:
    - Move your character controller movement code from FixedUpdate to Update (same thing for the camera) (horrible and disgusting solution - because of unstable collision detection with the character controller etc. :D)
    - You could also try adding kinematic rigidbody on the agent itself and then enabling the rigidbody interpolation? But this will not work if the NavMeshAgent component internally is not using the rigidbody.MovePosition/MoveRotation functions in case rigidbody component is present. It would still not be a perfect solution, even if it would work. But should suffice for the visual stuff :)