RootMotion module | Animate the HumanoidRootPart with ease! | Simple | No conversion needed

Root motion

View the GitHub repository here
Get the source code here

This module allows you to easily achieve root motion in your game with no extra steps required. This saves you the work of configuring forces or cframes in your script constantly to achieve your desired effect you want on the player’s torso. Now, you can animate the torso in any animation tool you want, and this module will do the rest of the work! Unlike other solutions, this doesn’t need require you to convert every single animation in your game to fit the format. This module will work out of the box on any animation which animates the torso. No extra work is needed from your end!

Features

  • Strictly typed - This means this utilises LUAU’s type solver to spot mistakes in your code inside the linter. This saves you time fixing bugs because you forgot something.
  • Performant - This module leaves a very low memory footprint inside the game, and the calculations take up very little CPU time
  • Out of the box - You don’t need to completely reimagine how your animations work in order to utilise this. All you have to do is animate and let the module do the rest of the work.
  • Simple API - This module only provides two self-explanatory functions for you to use.

Drawbacks

  • Primitive physics - This doesn’t rely on ROBLOX’s physics to apply it’s physics. While this means you can’t get flung by any external parts, it also means you may not be able to experience pushbacks if you want to.

FAQ:

Why should I use root motion?

Root motion allows you to animate the HumanoidRootPart (HRP) of rigs. This is important if you rely on the HRP for hitboxes or you don’t want the animation to fade back to it’s original position after it ends. Below is a clip of a simple animation (don’t mind my bad animations) being played with and without root motion. The difference is night and day;

What rigs does this module work on?

Currently, this module only works on R6 rigs, however I don’t imagine it to be too hard to apply this to R15 rigs. I just don’t have the time to check if it works and fix any potential bugs.

What are alternatives to this module?

You could always strip the torso keyframes out of your animation and then manually position it using CFrames. However this is tedious. Another solution is to use bodymovers to move your rig around. This is easier to do but can be hard to perfect for small details you’d like to implement.

I have an issue or suggestion!

You can either comment under this DevForum post with your problem, or open up an issue on the GitHub repository (linked above). If you’d like to contribute then feel free to open a Pull Request on the GitHub!

This module is probably the best alternative to this module, however it’s API is much more complex. Moreover, extra work is needed to convert your animation to an acceptable format for the module to work. This module doesn’t need any extra work from your end to achieve root motion.

API

type Configuration = {
    ["Whitelist"] : {Part | BasePart}?,
    ["AlignHRPCFrame"] : boolean?,
    ["MaintainVelocity"] : boolean?
} --// If left nil, the booleans will be assumed to be false

:StartCorrection(Configuration : Configuration)

Starts correcting the character’s HRP cframe to keep it in line with the torso’s animation.

  • Whitelist - allows you to add extra parts / models for the collision detection to ignore. Your character will noclip these parts when being animated instead of stopping in place if it comes into contact. Parts with no collision are automatically ignored.

  • AlignHRPCFrame - Aligns the HRP with the player’s camera look direction. This is useful if you want all your animations to start at the same level, regardless of the player’s prior orientation or not. For example, if you play an animation with this setting off and the character looking at the floor, then they’ll be lower than if they were standing. This setting allows you to avoid these situations.

  • MaintainVelocity - This maintains the character’s velocity after the root motion ends. Normally after root motion, the character will just freeze up if you want to ragdoll them afterwards since ROBLOX doesn’t automatically update their velocity. This updates the velocity for ROBLOX so the character’s motion is maintained and any after effects look natural.

RootMotionModule:DestroyDependencies(ReverseAllEffects : boolean) 

Stops the HRP from correcting it’s CFrame in line with any animations

  • ReverseAllEffects - Reverses all effects the module applied to the character’s physics and makes the character automatically stand up as if nothing happened.
    If left false, the character will stay in the:
  • Physics state
  • No autorotate
  • Camera subject is the head
  • All limbs have no collision
14 Likes

Helloooooo

So I just discovered a bug based off the replication of the root motion due to my oversight. Basically on other clients, since the animation is playing with the torso rotating, the other clients will already see the animation moving. However, what this module relies on to stop the animation from overflowing after setting the HRP’s CFrame is the setting of the RootJoint’s .Transform to the identity CFrame. This eliminates all torso offsets and matches it with the HRP’s CFrame so the animation doesn’t overflow. Of course, .Transform property doesn’t automatically replicate. This means that while the torso gets animated on other clients, so does the HRP. This leads to a pretty annoying visual bug where it looks like the character rotates more than they should or move further.

The fix is to just fire a remote event whenever the rootmotion begins and when it’s received (on other clients), just start a presimulation event which sets the character’s rootjoint’s transform to the identity cframe. Then when the rootmotion ends, send a signal to end the transform and simply disconnect the event.

Sorry for the inconvenience!

2 Likes