Download

Need C++ guidance creating actor class with Root motion.

Hi,

I need a C++ pro out there to give me pointers or some guidance as to how to go about accomplishing this task.

I need to create a new custom class exactly the same as the Actor class except I want to add root motion support to it.

I’ve been looking everywhere and all the tutorials are basic and don’t cover or attempt this. And I don’t have C++ experience to fiddle with the code.

To my understanding I need to copy the actor class code and add root motion code to the lines somewhere. Or the reverse to copy the character class BP code which has root motion but remove everything else to make it as bare bone as the actor class. Whichever is easier.

Any pointers would help, thanks in advance!

Here’s how:

Place this in your actor’s tick



    if (SkeletalMeshComp->IsPlayingRootMotion())
    {
        FRootMotionMovementParams RootMotion = SkeletalMeshComp->ConsumeRootMotion();
        if (RootMotion.bHasRootMotion)
        {
            const FTransform WorldSpaceRootMotionTransform = SkeletalMeshComp->ConvertLocalRootMotionToWorld( RootMotion.GetRootMotionTransform() );
            FQuat NewRotation = WorldSpaceRootMotionTransform.GetRotation() * GetRootComponent()->GetComponentRotation().Quaternion();
            GetRootComponent()->MoveComponent( WorldSpaceRootMotionTransform.GetLocation(), NewRotation, true );
        }

    }