Ok, so I work through a lot of important issues during this post and I come up with an imperfect solution that I am going to leave aside for now because I want to continue my journey in other ways. The video below is the working solution I am moving forward with at this time. If you are interested in the journey that got me here, read on past the video.
Here are the relevant changes to the Zombie Animator script. Essentially Update Position toggles have been commented out and we let the Agent do its thing with one exception: in the callback On Animator Move, the speed of the Agent is computed using the Animator. This has the effect of producing the correct speed but not the correct look. It is good enough for now.
I turned on Shadows and added a Hit animation and now I know how bad things really are. Here is a non-exhaustive list:
- The Zombies do not touch the ground with Nav Mesh Agent positioning turned off.
- The Idle state does not touch the ground even with it turned on.
- The Hit animation pushes the Zombies off the ground.
- When dead, the Zombies still rotate to face the player.
- Turning Physics on doesn’t help.
And a potential solution:
I got rid of a capsule object that required everything to have a weird offset. Nav Mesh Agent was at 1. It can be zero with the Synty Mesh because the the character transforms are at the feet. This means the transform of the Zombie can be zero instead of -1. This doesn’t do much for the feet floating off the ground just yet, but it’s a start.
The next task will be to get the Zombie’s feet on the ground.
I found the article on How to Fix Floating Feet on the Mesh Tint website. It essentially comes down to understanding what you should Bake Into Pose and what you should let the Root Motion deal with. This article has what seems to be a popular answer on that subject.
Baking the root transform into the pose prevents that part of the transform from affecting Root Motion.
If you don’t want the Transform to turn, check rotation.
If you want the Transform to stay on the ground, check Position (Y).
If you don’t want the transform to move about on the ground, check Position (XZ).
We want our Zombie’s feet firmly on the ground. So we want to check the Position (Y) box.
The final adjustment is to apply Foot IK to the State in the Controller.
And here’s a test of the improvements on the Idle animation for one of the Zombies.
I made some more adjustments on the fly for the Movement, Death and Hit animations which I detail in this video. I also notice a huge flaw in the plan.
Can I summarize in a nutshell what I learned?
- Freezing the Position (Y) is critical for the various animations.
- Foot IK is window dressing.
- Stair wells are a bitch.
The best way to start the Zombies off on the Nav Mesh is to have the agent updating the position at the start of the game. The following are changes to the Zombie Animator component. Whenever we need to use Root Motion, we disable the Nav Mesh agent and let em go!
This bit of code is begging (BEGGING) for a state machine. I resist! This is throw away code and I am already deep down a rabbit hole.
It’s worth noting that removing the Capsule Collider and adding a mesh collider onto the Mesh means that the Collider is now on a child game object. We need to cast up to the parent in order to find the Target now.
Similar changes need to be made to the Impact Handler as well.