Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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!



    Last edited by William K; 09-20-2018, 06:17 PM.

    #2
    Here's how:

    Place this in your actor's tick

    Code:
        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 );
            }
    
        }

    Comment

    Working...
    X