I’m trying to implement a controller for an NPC that follows a grid like path using root motion.
At the moment, my script is constantly checking if the character has reached its destination and/or requires rotation, but the inaccuracies (even with tolerances) are causing me a lot of grief.
From what I’ve ready so far, it looks like MatchTarget is the solution to this problem. Are there any good tutorials that make use of MatchTarget for things like climbing, jumping, and path-following when the exact destination is known?
I’m fairly certain I can figure out turning and basic walking with a bit more experimentation, but implementing climbing and jumping (when the exact destination is known) seems like a daunting task with only a few minor examples to work from.
Lastly, the targetNormalizedTime parameter is confusing since I have no way of knowing how many times the animation must loop in order to reach a particular destination.
After a bit more experimentation it doesn’t appear as if you can use MatchTarget to move a figure to a specific location over time. I thought I could try something like this in FixedUpdate, but it just jumps to the location.
I don’t think MatchTarget is best for the case you are describing.
Have you tried LERP (for position) and SLERP (for rotation)? Unfortunately you will have to give up the root motion to control your position precisely. You can just turn off root motion while your figure is moving to the specific location using LERP and then turn off the LERP and turn on the root motion again once the location is reached.
Since I made this post, I gave up on trying to use root motion for walking and running. I’m now using physics and curves to mimic human acceleration / deceleration. Of course, it looks like my character is sliding all the time, which I hate.
Recently, I did manage to get root motion working for climbing.
The trick was to uncheck “Bake Into Pose” on the animation and manually update the position and rotation within OnAnimatorMove().