Forward speed never goes down to zero

Hey,

After applying the structure from the lecture with Character, Player and Enemy I have noticed a bug that once the player moves to the destination the ForwardSpeed parameter in animator is constantly changing causing the player to wiggle.

What could be causing this? Its changing super fast.
Screen Recording 2022-10-08 at 11.07.41

Edit: Removed the animator and my character is moving in place, I can see in the Transform component that his position and rotation is changing.

Edit2: After removing the Enemy prefab from the scene the issue is gone, re-adding adds the bug again.

Edit3: Narrowed it down, the issue is caused by NavMesh Agent on the enemy, if I disable it the issue is gone.

Edit4: After creating another agent and changing the agent from Humanoid on the enemy Prefab Variant the issues is gone.

image

This is usually due to floating points being used. It is highly unlikely for the position to become 0. The NavMeshAgent component has a ‘stopping distance’ field. This is the distance that is used by the agent to determine if it is close enough to the target to stop. Try adjusting this value.

What happens is that the agent may get to within 0.1 of the target (for example), but after the next frame it has moved past it. So, it tries to go back to it, but moves past it again. This happens perpetually causing the wiggle. The stopping distance helps prevent this by letting you control how far away from the target the agent will stop. If the agent wiggles when it is within 0.1 of the target, setting the value to 0.2 may help because the agent will stop before it starts wiggling. You just need to find a stopping distance that is slightly larger than the distance the agent moves in each frame

1 Like

Thank you for your reply, however this does not seem to be the issue here.
If it was then I should be able to reproduce it with enemies Nav Mesh Agent enabled or disabled.

The issue only happens when two object have Nav Mesh Agent set on the same Agent Type, in this case Humanoid.

However, out of curiosity where would I go to change the value you refer to?

Found solution in this post: Enemy Unit AI / Animation Glitch

Was it the Mover trick or changing when the ResetTriggers were activated that did the trick?

In my Mover.cs file in the Update function I have added following code as per your @Brian_Trotter instruction there:

        if (
                !navMeshAgent.isStopped &&
                navMeshAgent.remainingDistance < 0.01f
            )
            {
                navMeshAgent.isStopped = true;
            }

You mentioned stopping 1f before the target but I found that value too big as it causes a visual bug where my character stops too far away from the target, much smaller value was sufficient.

So in the end it was the thing @bixarrio mentioned but I have also noticed that it only happened when other GO with NavMeshAgent set to the same Agent were around.

Probably some Unity quirk, that just cannot be explained. :sunny:

We usually use larger acceptance radiuses because of this very issue. If you’re comfortable with 0.01f, though, then it’s fine to use this.

I have no explanation for the agent type quirk. The Agent type is virtually ignored by the built in navmesh system, and generally only becomes truly useful with the NavMeshTools (which allow multiple meshes based on the Agent’s type.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms