Root motion based locomotion combined with Ai Decision Trees... in C++.

Has anyone here worked with that?

I’m trying to implement root-motion based locomotion system in C++ (actor is derived from ACharacter). The system is supposed to be driven by AI decision trees, with minimal modifications.

I do have root-motion-based player-controlled character movement, and now need to plug AI in.

The thing is unreal movement system works in rather unexpected way. Move To command (from decision trees) doesn’t perform actual movement, and instead sets “RequestedVelocity” field of UCharacterMovementComponent. Well, to be more precise, it interacts with UPathFollowingComponent which sets RequestedVelocity.

UCharacterMovementComponent alone has 250 kilobytes of code in it and doesn’t look like it was made with extensibility in mind (already had to subclass it to make sure root motion doesn’t override rotation).

To make root motion work I literally need to pinpoint a location where component knows in which direction it wants to go, but haven’t moved yet and I need to set motion control variables at that point.

Has someone here done that?

Working with this portion of code takes a bit too much time for my liking, and it would be nice to have some hints to speed things up.

I’m currently contemplating if dropping ACharacter base class and subclassing APawn instead would be a good idea (single player game, no networking) in those circumstances - I’m not sure if I’m getting any benefit from ACharacter functionality.

I find the lack of replies disappointing.

Anyway, I figured it out.

For motion control, you need to to create subclass of UPathFollowing component and override

	virtual void OnPathFinished(EPathFollowingResult::Type Result) override;
	virtual void FollowPathSegment(float deltaTime) override;

OnPathFinished is called when movement stops, and FollowPathSegment is called when application follows some segment.

Also, rotation is handled within

virtual void AAIController::UpdateControlRotation(float deltaTime, bool updatePawn = false) override;

So, in case of root motion, it’ll be necessary to subclass this one too.

Basically, you need to set motion control vairables within FollowPathSegment, zero them when OnPathfinished is called and handle rotation in UpdateControlRotation. Direction in which Ai wants to look is available via AAIController::GetFocalPoint().

Anyway, problem solved, unsubscribing from the thread.

Thanks for good solution!

Hey! Thanks this is awesome. Its exactly what I need right now.

I know this is an old thread but its worth the shot.

I’m Having the same problem. In root motion you need to set the horizontal and vertical input of the locomotion. In the function followpathsegment, what values did you get in the controller to covert it in those input? I dunno if there is something like MoveVelocity for the next target point or did you just based it on the UpdateControlRotation and you set the input values based on the forward of the UpdateControlRotation?


I’ve check the existing code in unreal. I used “GetCurrentTargetLocation() - MovementComp->GetActorFeetLocation();” to get my movement input. anyways Thanks for this. It was such a big help for me! :slight_smile: