AI Driven Locomotion with Root Motion

I want to replace my In Place animations to Root Motion for AI/Enemies. But when I do this, don’t know how to handle AI movement.

Any idea for this implementation?

You should probably drive all standard locomotion animations/blendspaces normally, eg in place with velocity and direction fed into the blendspace.
Root motion will be best used for one off animations such as hit reactions or attacks.

This is a very complicated matter :slight_smile: To use root-motion animations for locomotion you’d need a dedicated solution for locomotion planning that would be taking a navigation path and was figuring out a combination of available animations that would more or less follow the path (or the next N segments of the path). UE4 doesn’t have a subsystem like that, sorry.

Cheers,

–mieszko

Hi Mieszko, will root motion cause the AI to leave the navmesh or is the end of navmesh like a collision where root motion can’t push the AI off?

Root Motion just converts animation translation to velocity that is applied to the AI’s character movement component. It will move them off the NavMesh.

Dzeligman is correct, currently root motion doesn’t care about navmesh at all. However this should be pretty easy to address - just add an extra step to actual movement that would clamp pawn’s root component’s translation to navmesh. I think UCharacterMovementComponent::PerformMovement should be a good starting point.

Thanks for the answers! I only use blueprints. So we currently can’t use rootmotion for AI at all in UE4(with blueprints)? How do all the other games handle this where all the AI uses root motion? As far as I know it’s possible in Unity.

Not out of the box, no. It’s a missing feature you might say.

Can I somehow simply clamp the character movement component location to be on the navmesh so that it just never can leave a navmesh, in blueprint?

The only thing you can do in blueprints in this regard is every tick check if AI left navmesh, and if so teleport it back to the remembered last “good” position. This is a hack but should give you what you need. And I’ll file a feature request so that character movement component would have an option for doing the clamping automatically.

Has this feature been implemented yet ?

Any other solution yet ?

it’s so simple, make your AI Character look at Path Points instead of using Simple Move To Actor method, that way you will get use of AI Navigaiton for your AI Characters without forcing them to Move by their CharacterMovement Component, and then you will have the ability to move anywhere using root-motion method.

I made this simple blueprint, and my AI Character follows my Main Character without any intervention of CharacterMovement, only animation root-motion is driving my AI Characters :wink:

as you can see, I have used Find Path to Location Synchronously to get the path point Number 1 as shown…

…then I made my AI Character Look At Path Point Number 1 - we only manipulate rotation here not the movement, therefore, we can make our AI move (or jump or punch or sing whatever you like) according to his root-motion animation separately.

now I could have him THINK like an AI but with root-motion movement. :wink:
he can find his path to the Main Character with a AI Navigation System Mind, but with root-motion movement. that’s because we only manipulated his rotation. I hope this helps, and this is how I deal with my AI Characters, I never use CharacterMovement method for them.

NOTE:

  • you should make sure you get the path point number [1] from the array of Path Points, any other number will not get the desired result for your AI.
  • make sure the Filter Class in the function is set to RaycastFilter_UseDefaultArea option as shown in the first picture.
  • make sure you have generated your Navigation Mesh Bounds in the level or particularly.

message me if you have any questions further.

2 Likes

Had same problem, I love you. It just works.

what about rvo avoidance?
dont work for me if Ai use rootmotion

Does the above approach adjust dynamically? For example, if anything about the environment changes, is there a function that notifies you to find a new path? Otherwise, it seems that you would just continue looping through the initial set of points found without adjusting for changes in the environment.

Thank you this solution is perfect.
However I’m having problems with the rotation.
If the AI needs to rotate like 90º or 180º it’ll just snap into that rotation. I’ve been trying to get it to slow into it, but nothing seems to work. Tried changing the rotation speed in the character movement options, but didn’t really think it would do anything, and it didn’t. Tried using finterp to and rinterp to but did nothing or the AI just started walking away from my location, and rotated away from me. If i started going after it it would always keep its back to me, which was kinda funny. Any ideas on how to make the rotation smoother?!

alt text

Apparently i managed to solve it. Here’s a screen if anyone’s getting the same issue

1 Like