NavMeshPlus icon indicating copy to clipboard operation
NavMeshPlus copied to clipboard

AI Jittering/Not moving (New Workaround/Fix?) - [Issue]

Open MikeSemicolonD opened this issue 3 years ago • 1 comments

I've been playing around with this package for a few months and I constantly come across this bug mentioned in Issue #32 and in the Wiki.

The workarounds all work inconsistently because you're adjusting either the position of the destination or the agent to compensate. So there's no guarantee that your NavAgent won't jitter/stop when you use those workarounds..

This bug occurs for me when the NavAgent navigates straight upwards or downwards and the x position of the destination closely matches that of the NavAgent's x position.

After playing around with it I found another workaround I wanted to post. Maybe this could be integrated into the Repo, but I don't know if it warrants a change to just the wiki or to the code itself.

The Fix/Workaround:

Set the X-Axis rotation on the NavMesh to slightly more than -90, like -89.999 or more, or until NavMeshCollectSources2d warns you that it's not -90 then Bake.

After I did this, my NavAgent was able to move up and down between waypoints consistently.


This new workaround points to something that's definitely internal to the NavAgent, (obviously beyond the scope of this repo) but if I were to guess I'd say the NavAgent is handling this NavMesh like a slope so it constrains itself in the process of going up or down.

MikeSemicolonD avatar Sep 18 '22 14:09 MikeSemicolonD

Hello @MikeSemicolonD

The fix you suggested sounds legit. My theory is that Agent has no knowledge on vertical climb (3rd dimension). So if agents "movement" point straight up (default Y axis), agent just stop moving, ignoring his rotation, alignment and distance.

I will test it and add to wiki, maybe it can be added as an option on NavMesh - "Enable agent jitter workaround"

Thank you for a feedback.

h8man avatar Sep 18 '22 15:09 h8man

@MikeSemicolonD

I tested, it helps. The side effects are really minor, but still we can have issue with calculus.

Anyway, not 89.98 s a standard navmesh rotation.

h8man avatar Sep 23 '22 11:09 h8man

@h8man

I agree, it's not a nice rotation number anymore so there's potential for the NavAgent to do something erroneous.

This workaround fixed my particular issue so I'll close this but if I come across more bugs pertaining to this I'll mention it here.

Thank you for pushing a fix.

MikeSemicolonD avatar Sep 23 '22 14:09 MikeSemicolonD

yes, it can.

If somebody make Z ordering of sprites, it can pop-in and pop-out of the scene as Agent moves slightly on Z. But, I have numerous reports that Agents drifts on Z axis. So anyway you need override presentation layer and update gameobject manually.

And as always I say: I never used Agents in my development, they to limited for me. But now I have motivation to add agent component to address such an issue.

h8man avatar Sep 23 '22 20:09 h8man