Hi, I think the problem you have is linked to Update and FixedUpdate and the way the navigation works.
What I think is that the navmesh internal engine will only update the position of your enemy during a FixedUpdate (just before or after all FixedUpdates, probably because pathfinding depends on collisions that are also updated during FixedUpdates). You are changing the navmesh destination during Update, and I guess your player moving code is in Update too.
You also know that sometime you can have multiple Update called when only 1 FixedUpdate is called, depending on the project’s physics settings and the current framerate.
Example: U,U,FU,U,FU,U,U,FU
Then, imagine there is U,FU,U,FU : your enemy will go toward the player during a FU (coz physics&navmesh are updated during FU), and the camera follow the player during a PU (there will be exactly as many PostUpdate as Update). In this case, everything is fine, the camera is not late or in advance in following the player, and the enemy is also not late.
In the case U, FU, U, U, FU: the player will change position during the two “continuous” U. The camera will change position during the 2 U (=PU), but the navmesh will only update the destination during the FU. Then, the enemy will “be late” while the camera will be exactly on time.
As the sequences of U and PU are quite random, sometimes the camera and enemy are not in sync, causing the jitter. That also explains that if either one of them is static, everything looks fine.
Now, to fix this: I don’t know the navemesh system very well so I don’t know if there is an “interpolate” flag like there is in the physics system. Maybe the navmesh will use this flag if there is a Rigidbody on your enemy: if so, you could try setting the interpolate flag to the “interpolate” value.
Something you can also do is update your camera with some damping:
transform.position = Vector3.Lerp (transform.position, player.transform.position+offset, Time.deltaTime * Damping). Damping being a public float field that you can tune to have the camera following “slower” or “faster”, try different values. This might be enough to eliminate the jitter.
If this doesn’t work, I would make sure everything is in sync:
- Change the priority of your player script in the project settings (setting this script to a value like “-10”) so you can be sure it’s updated before all enemies.
- Update the enemy’s navmesh destination during a FixedUpdate instead of Update.
- Define a public Vector3 CameraTarget in your player’s script. In the player’s FixedUpdate, set CameraTarget to transform.position.
- Use the damping code to update your camera during FU but now, instead of using player.transform.position, use player.CameraTarget.
Doing this, everyone, enemy + camera will target the same position that is updated during FixedUpdate so the navmesh system will use this one too, hopefully fixing your problem (make sure to use the damping on the camera or the camera will not be smooth if it targets a position updated during FixedUpdate)
I’m not 100% sure that this is the cause of the problem, I hope one solution will work, please tell me if it does in the comments