Root motion
View the GitHub repository here
Get the source code here
Insert the ROBLOX model 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?
This currently works on both R6 and R15 rigs. If you use a custom rig then you will need to adjust some parts of the module to account for this.
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 horizontal look vector. 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, Replicate : 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 -
Replicate - Enables or disables replicating this to other clients. Read the bottom of the post if you want to implement proper replication for this module.
RootMotionModule:MaintainTransform(Enabled : boolean, Replicate : boolean)
Continues correcting the transform property even after the module has stopped, but doesn’t correct the HRP’s CFrame. This is useful if your animation fades out, but you don’t want to move the HRP back.
- Enabled - Either starts or stops the correction
- Replicate - Enables or disables replicating this to other clients. Read the bottom of the post if you want to implement proper replication for this module.
Replication
You may notice at the bottom of the module, there is code relating to remote events. If you’d like to prevent other characters overshooting their cframe’s, then you need to insert the code in a script. At the top of the module, there is also an event parameter which is commented out. Once you’ve inserted the code at the bottom of the module, you can add a remoteevent and uncomment that line. Throughout the module there are parts which are also commented out which fire that event. You should also uncomment those lines in order for this to work.
