How do i use Root Motion on AI in a multiplayer game?

Hello, i’m trying to make my AI use root motion on every animation, The game is multiplayer, which doesn’t recommend Root Motion on Everything, but my animations have so much different speeds that doing that by code would be a lot of work, will it still work? Right now my biggest problem is in the movement (starting and stopping), because since the capsule is being driven by the root motion i can’t go to the walk state by checking the GetVelocity() component. Since the AI uses MoveTo and other commands in the Behavior Tree, how can i trigger the Walk state and stop it accordingly?

Hi ****,

So you have a few concerns and questions here. I’ll address your concerns, then we can go over some solutions for you.

Always good practice to check Epic’s documentation. They go over using Root Animation, and the advantages of using it in order to push the character’s movement component rather than animation the mesh. Depending on what your monster is doing you can animate the mesh instead of using Root Animation. My own rule of thumb is that if it needs simulates with other objects in the world, such as an attacks - I’ll have it do Root Animation. When you’re just doing playback, such as a cut scene, Root Animation isn’t required.

What I’ve done in the past when I need the animation to simulate with objects but also keep the animations movement close the original animation. When you have for example a jump necessary for your character. The pawn would input jump, then I would tell the pawn to change its movement state to flying. Since Root Animation takes into account gravity, by putting it into flying - we ignore it. Then the character animates, and at the end of the jump’s height - an animation notifier events the Animation Blueprint. This then changes the Pawn’s state back to walking, and gravity is returned as normal.

That would result in the character jumping in the air, then being forced back down by gravity. So depending on what you’re trying to accomplish. You should be safe to use both, but understand the caveats to both operations then decide which you think is best in your situation.

-Peace

Hello peter, thank you for the reply :slight_smile: I ended up solving this question checking if the Path Following Status == Moving to find out if it’s moving or not. I use root motion for attacks but for movement also, especially my player, because he has so much different speeds that it would be insane to contemplate that by code using the character movement component to make the 1:1 relationship between the animation and how much he travels in the world. My biggest problem with using Root motion for movement is that it is not recommended for network so i still have to see if it works well in a network environment.

Why is it not recommended over the network?

Because it says so on the tooltip when you select Root Motion from everything.

How did you get root motion to work on your ai?? i’ve been trying to do this since forever, i’ve tried every tutorial but couldn’t get it to work for nothing. Would you mind telling me how did you get this to work with AI?

Hello, i got this to work setting Root motion for everything in the anim blueprint. Make sure all the anims have root motion enabled. To start walking i check Move Status of the AI Controller to see if it’s in state Walking. Make sure Enable Controller Yaw is true so that the control rotation defines the direction of the movement.

Can you be more specific? Or is it really THAT simple Lol

It’s really that simple :stuck_out_tongue:

Hey can you please give me a good description on how you got your AI to move with Root motion.

My main thing is that I want my AI to have smooth rotation while running or moving.
I’m not able to achieve that with normal character movement.

I’d grateful.

Thanks for the response.

Im basically making an animal game. I want my animals to resemble real world speeds. But when I scale them even 0.01, foot sliding starts.
Also the turning animation is pretty bad.
How are you calculating direction ?
That’s why I was thinking of root motion but im not sure if I should do it or not.
My game is full blueprint only so far, and im pretty new to UE4. Can you suggest me something or show a tutorial ?

Hey, if i remember correctly i set the option Root Motion from Everything in the animation blueprint so that he extracts root motion from animation sequences as well. If you want to do root motion rotations in place you have to disable Use Controller Rotation Yaw boolean that exists in the character and enable it back again when the animation is over. To smoothly face your target in terms of rotation, so there are no pops, i’ve overriden void ACharacter::FaceRotation(FRotator NewControlRotation, float DeltaTime) and did an interpolation:

FRotator OverrideRotation = FMath::RInterpConstantTo(GetActorRotation(), NewControlRotation, DeltaTime, 250.0f);

return Super::FaceRotation(OverrideRotation, DeltaTime);

I have been working on a basic concept for this implementation. If I get you right. you want to get use of Navigation Systems for AI but at the same time drive your characters with root-motion animations instead of using Character Movement for them;

the Idea is simple, though it’s a concept Idea but it’s applicable to many methods if you are gonna evolve it according to your AI desire. (whether you want him to Chase, or Randomly Wander, or Stop… etc.) and it’s all using root-motion animations for them.

My Idea was to make an AI chase Batman Character (which is my main controlled character) while AI use root-motion based movement to Move or Stop accordingly.

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 which is 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, punch or sing whatever you like) according to his root-motion animation separately and according to your animation states :wink:

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

Try this out, and see the magic :wink:

PREREQUISITE 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.

If it’s single player and the root motion is for the AI, i would so to go for it. Root motion in the player is more complex. I think you can’t override the FaceRotation function in blueprints, never tried it. I’m not sure if you can do it in Tick it’s not the best approach, but it might work as a workaround.

I may not getting you right, but can you clarify more for me. “FaceRotation”? “Root-motion for the player”?
what are you trying to really do? it might be of the same research I’m working on. and I may help you. because I’m also 100% using root-motion based movement for almost every character in my project. (whether Players, or AI’s).

I’m just advising him on how to get root motion in his AI, i’ve fixed this on my end a long time ago. Player root motion is also doable, i’ve done it myself, but it requires a bit more work because you no longer can use Add Movement Input to move, you have to work around that. In AI it’s easier because you’re not doing the movement itself, so you get it to work faster.

glad to hear that. :slight_smile: (y) I know it’s frustrating… I suffer the same thing too when I want to mix up CharacterMovement and Physics Calculations to my root-motion based Character. turns out that there are situations in the game that are not necessarily handled by root-motion and you find yourself obliged to use CharacterMovemnt. (when it comes to precise calculations) eg. moving horizontally while aligned to a ledge. this requires me to abandon the root-motion method. but on the other-hand I guess you could implement this using Blueprint Anim Graph (Modify Bone) method. :smiley:

I’ve used Razorflame’s Root Motion tutorials to get my player Root motion working.
Will that Anim Blueprint work with your system ?

Razorflame Root Motion tutorials:

I tried what you told me to with the blueprint, but it doesn’t seem to be working.

I’m probably doing something wrong.

And I’m using Behavior Tree “Move To” to get to locations.

I tried other Move to Actor / Move to Location nodes but they just lock AI or don’t move properly.
I can work anyother way but How to work Root motion ??

My Lion just moves slant even when walking straight.