Link an AI Paths Speed to RootMotion

So I found that If I don’t use rootmotion and let the AiPath move the character, local avoidance will work a lot better.

I also noticed that the max Speed and Desired velocity seem to play into this,

I was moving my characters via Rigidbody.velocity = _rootMotion where root motion was derived from the animator.deltaPosition/Time.Deltatime.

There has to be some way to sync the agents desired with the rootmotion speed,
I have tried
_aiPath.maxSpeed = (rootMotion).magnitude;
_rootMotion = _aiPath.desiredVelocity;

neither seem to quite nail it,
Could you please recommend the proper way to sync root motion and agent speed ?

There is an included script called MecanimBridge that you might want to have a look at (check how it is implemented). I’ve wanted to have an example scene for this script for a while, but it turns out it’s tricky to find models and animations that I can actually redistribute with a correct license. And the ones from Unity that I tried weren’t quite what I wanted.

That script was used to make this video:

However, when it comes to integrating mecanim, pathfinding and local avoidance I don’t really have a good solution. I have tried a whole range of different approaches over the years, but I haven’t really found one that works satisfyingly. I also mentioned this in a previous thread.

I’ll check it out,
but so far I did have luck with this implementation, it seems to be working so far, I just turned off calculating root motion for the AI characters, and apply the root motion to the max speed.


            ///Sync AgentSpeed with RootMotion
            var desiredSpeed= (Soldier.Animancer.Animator.deltaPosition / Soldier._deltaTime).magnitude;
            var newSpeed= Mathf.Lerp(_lastSpeed, desiredSpeed, 0.5f);
            _brain._aiPath.maxSpeed = newSpeed;
            _lastSpeed = newSpeed;