Root Motion Explained (Unity Tutorial)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

This post appears to be a direct link to a video.

As a reminder, please note that posting footage of a game in a standalone thread to request feedback or show off your work is against the rules of /r/gamedev. That content would be more appropriate as a comment in the next Screenshot Saturday (or a more fitting weekly thread), where you'll have the opportunity to share 2-way feedback with others.

/r/gamedev puts an emphasis on knowledge sharing. If you want to make a standalone post about your game, make sure it's informative and geared specifically towards other developers.

Please check out the following resources for more information:

Weekly Threads 101: Making Good Use of /r/gamedev

Posting about your projects on /r/gamedev (Guide)

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

👍︎︎ 1 👤︎︎ u/AutoModerator 📅︎︎ Sep 04 2021 🗫︎ replies
Captions
hi guys today we're going to look at how we can move a character using root motion in other videos we've explored how to animate a character but so far we've always controlled the actual movement from a script with root motion the movement is built into the animation and it's the animation that determines how the character moves rather than the code this allows us to move characters in much more complex ways and have the movement perfectly synchronized with the animation okay we're going to start with this scene that has a character we've downloaded from mixamo.com if you want more details on how to import characters from miximo we have a dedicated video that goes into this in detail to demonstrate how root motion works we're going to head back over to miximo to download an animation we'll search for salsa dancing this animation has lots of complex movements that will be extremely difficult to replicate in a script we'll click download we'll choose fbx for unity and select without skin to just download the animation without the character then we'll click download and save the animation to the assets folder of the project back in unity we'll select the animation and then select the animation tab in the inspector we'll tick loop time and loop pose to have the animation loop forever we need to click apply to save the changes we'll then expand the animation and drag the triangle icon onto the character in the hierarchy this will assign this animation as the entry state for the character let's press play to see what happens the animation plays and the character dances around if we select the character in the hierarchy and look at the transform of the character though we can see that the position and rotation of the game object aren't actually changing so visually the character is moving but the underlying game object is completely static let's stop the game and add a box collider component to the character we'll then press play again if we switch to the scene view we can see that the box collider isn't moving this means that we can't properly detect collisions with the character while this animation is playing let's stop the game and change it to use root motion the first thing we need to do is tick the apply root motion checkbox on the animator component of the character for root motion to work we also need to change the character and animation to use the humanoid animation type we'll select the character in the assets panel and select the rig tab then we'll change the animation type to humanoid we'll click the apply button to save the changes this will result in an avatar being created that maps the bones of the character to the generic bones of unity's humanoid animation system if you want more detail on this then take a look at our video on animation retargeting next we'll select the animation in the assets panel and change this to humanoid as well this time we need to change the avatar definition to copy from other avatar we'll select the character's avatar as the source then we'll click the apply button to save the changes the final thing we need to do is tell the animator to make use of the avatar we'll select the character in the hierarchy and set the avatar now let's press play to see what happens the animation plays and looks exactly the same as before but if we look at the transform of the character we can see that the values are now changing and if we switch to the scene view we can see that the box collider now moves and rotates in sync with the animation to show off the power of root motion even more we're now going to add a walking animation we'll stop the game and head back over to miximo we'll search for a walking animation in the past we've ticked the in-place checkbox as we were controlling the movement in a script this time we'll leave it unticked as we want the animation to move the character forwards we'll click download and save it to the assets folder as before back in unity we'll select the walk animation and then select the animation tab in the inspector we'll tick loop time and loop pose to have the animation loop forever before clicking apply to save the changes next we'll go to the rig tab and set the animation type to humanoid we want this animation to use the same avatar as before so we'll select copy from other avatar and then set the avatar we'll then click apply to save the changes next we'll expand the animation and drag the triangle icon onto the character we'll then select the character in the hierarchy and double-click on the animator controller this will open the animator window showing the animation states and transitions at the moment the dancing animation is set as the entry state and the walking animation isn't connected to anything we'll add some transitions to go from dancing to walking and back again to do this we'll right click on the dancing animation and click make transition then we'll click on the walking animation this has now created a transition from the dancing animation to the walking animation we'll do the same to create a transition back the other way now we need to add a parameter to control these transitions we'll click on the parameters tab and then we'll click on the plus button and add a new boolean parameter we'll call this is walking now we can use this parameter as a condition to transition from one animation to the other we'll click on the transition from the dancing animation to walking we'll then untick the has exit time checkbox this will allow us to set a condition for when to transition from dancing to walking for this one we want it to be when the is walking parameter is set to true we'll click the plus button to add a new condition and by default it's added what we want then we'll follow a similar process for the transition from walking to dancing we'll select the transition and untick has exit time we'll then click the plus button to add a condition this time we'll set the condition to be when is walking is false if any of this seems unfamiliar then take a look at our video on animation transitions where this is covered in much more detail now we've set up the animator the next thing we need to do is create a simple script to set the parameter used in the transitions we'll click on the character in the hierarchy and add a new script component we'll call this script movement then we'll double-click the new script to open it in the editor this script is going to be very simple first of all we'll create a field to hold a reference to the animator component then in the start method we'll get the animator component and assign it to this field in the update method we'll check if the spacebar is being held down if it is we'll set the is walking animation parameter to true on the animator we'll then add an else statement in here we'll set the parameter to false so the character will start off dancing and when the space bar is held down it will transition to walking when a space bar is released the character will transition back to dancing let's save this script and switch back to unity to try this out the character is dancing as before but now if we press space the character will walk in the direction it's currently facing if we release the space bar the character goes back to dancing so without writing any movement code at all we now have a character that can move all around the scene using root motion you may notice a slight issue though as the character moves around and we keep transitioning from one animation to another the character starts rising off the ground this is because the dance animation changes the y position of the character then when we press space it starts walking from whatever y position we're currently at the next time we switch back to the dance animation it starts from this y position so over time it gets higher and higher let's stop the game to fix this we'll select the dance animation in the assets panel and on the animation tab we can see various options relating to root motion here we can control what aspects of movements are controlled by root motion and which ones we bake into the animation we have options for rotation y position and xz position so to fix this particular issue we can tick bake into pose on the root transform y position this will stop the animation affecting the y position of the character and we'll bake it into the animation instead let's click apply to save these changes we'll then do the same for the walk animation you'll notice the green and red lights next to each setting this tells you whether it is a good candidate for baking so for the walking animation it is green for rotation and y position as the start and end values are similar for these it's red for the xz position as the start and end values differ too much if we bake this the character would walk forward and then snap back to the original position before walking forward again let's press play to try this out now we can see that the y position is no longer changing and when we walk the character will always stay on the floor there may be times when you want to use root motion for one animation but not for another to do this you can bake everything into the animation for example we'll stop the game and select the dance animation then we'll tick the check boxes to bake the rotation and xz movement into the animation we'll select original from the based upon drop downs to use the original values from the source file we'll then click apply and press play to see what happens if we switch to the scene view and select the character in the hierarchy we can see that the box collider is no longer moving in sync with the animation this is because root motion is no longer being applied for this animation when we press the space bar the character still walks but it will always walk in the same direction because the rotation of the character is no longer being changed by the dance animation that covers the fundamentals of root motion in a future video we'll look at how to use root motion when moving a character with a character controller component hope you found this video useful please leave any questions or feedback in the comments and subscribe and click the bell icon so you don't miss the next one if you find our channel useful and would like to help support our work you can find us on patreon and coffee.com thanks guys
Info
Channel: Ketra Games
Views: 25,047
Rating: undefined out of 5
Keywords: Root Motion Unity, Root Motion Unity3d, What is Root Motion, What is Root Motion Unity, Root Motion Explained Unity, What is Root Motion Unity3d, Root Motion Explained Unity3d, Unity, Unity Tutorial, unity3d, Unity3d Tutorial, Learn Unity, Indie Game Development, Game Development, Learn Unity3D, Unity 3d, Unity Tutorials, unity 3d Tutorial, Tutorial, Game Development Unity, Unity Game Tutorial, Unity Tutorial for Beginners, Unity Beginner Tutorial
Id: Xl_5roq4UlI
Channel Id: undefined
Length: 11min 49sec (709 seconds)
Published: Fri Sep 03 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.