Hi, I am trying to use root motion for my humanoid enemy AI characters which use a unity navmesh. I’m running in to a lot of issues with the charachters walking through walls and objects even though they are clearly baked onto the navmesh. I’ve been doing a bit of searching and it seems like root motion will overrule all colliders etc? is this correct? If so is there any way I can stop my characters running through walls and obstacles?
Part of the issue seems to be that the navmesh agent doesn’t nicely follow the character, instead it lags behind or pushes ahead unless it is pulled back using :
// Pull agent towards character
if (worldDeltaPosition.magnitude > agent.radius)
agent.nextPosition = transform.position + 0.9f*worldDeltaPosition;
however this doesn’t keep the agent centred with the character, usually the character will sit on the edge of the actual agent radius, meaning they often end up walking or getting pushed into walls. Currently i’m using the above code but with 0.01f*worldDeltaPosition and that seems to have given me the best results… however there are still heaps of issues, especally when getting the enemy to move to specific positions in the world, such as cover, most of the time the enemy will end up inside the cover position… rather than behind it.
one of the causes is possibly that the agent stops updating when the character is stopping, but as the animations blend between walking/running and idle over a second or so, the actual character ends up further forward of the agent, this often ends up with the agent in a wall or past the point it needs to be.
I’ve tried increasing the agent radius but this doesn’t help, if anything it makes it more error prone. I’ve also set agent.Warp to be called every few frames and that helps but it messed up a lot of other stuff, I guess it recalculates the path every time it happens? currently I have it called every second if the character is stopped in order to make sure the agent and character are aligned when it starts moving again…
I also tried the other unity suggestion of pulling the character towards the agent but this gave pretty unusable results.
My code is more or less the same as the code from this tutorial https://docs.unity3d.com/Manual/nav-CouplingAnimationAndNavigation.html
I’m really struggling with this as I’m in the process of trying to code a cover system for my AI but I can never get it to stop in the right place. Has anyone got any suggestions or has anyone used root motion with a navmesh agent before for AI characters, especially ones that need to navigate “busy” areas?