Day 86 — Implementing Animations: Controller and Idle Animation
Hey and welcome!
Before we start getting into some more technical parts for this project I’m going to be setting up the Player we imported last time with their own animations. The animations themselves will be grabbed from Mixamo and then I’ll go over how to set up the animator controller so that we can transition from idle to running etc.
I’m also going to be importing one of the character models they have in Mixamo so if you don’t have your own this will be helpful for you as well.
Here’s the link to Mixamo if you’ve not heard of it before, it will prompt you to create an account but everything you see is free to use, including the character models!
First things first, pick out an idle, running, and jumping animation from Mixamo that you like and choose to export as an FBX for Unity with the skin when you download them.
When you choose the running animation make sure that you select the In Place option so that the character is running on the spot like above. If you need a character model you can select one in Mixamo and it will replace the default Mannequin when showing off animations. When you export with the skin it will take the character model along too!
Now import the model into Unity if you haven’t already and you should be able to see 4 options for it in the inspector when you click on it:
Only two of these are going to matter though for our purposes, in the Rig tab make sure you switch the animation type from Generic to Humanoid and then apply the change. This will also create an Avatar that we’ll be using later. Next head to the Materials tab here and for the Location option choose Use External Materials (Legacy) and apply this change in order to bring the colour back to the model as you may have found it looking very grey initially.
Now simply drag and drop it as a child of the Player object and you’re all set with the model part of all this.
Setting up the Controller
Now it’s time to look into animations, in the model you imported you’ll notice that there’s an animation in each one which only shows up in the project view and disappears when you drag it into the scene. Click on this animation and press CTRL + D in order to separate it from the model file and then store it in an animations folder. Do this for all the animations you imported, we don’t have use for the model file as a whole anymore so you can delete the two that you didn’t move into the scene to use as your player. (Make sure that you set the rig for them to humanoid before you separate and delete them!)
In your animations folder create a new Animator Controller, open it up and drag and drop your idle animation into the space in order to get something like this:
Now on your model in the scene add an animator component to it and use this controller as the one it looks for and use the avatar you created earlier for the option here as well, run the game and test out your animation.
That’s the first animation sorted out, I initially had all three animations covered in one article but it ended up being a bit longer than intended! There’s a lot to cover so the running and jumping animations will follow this one in their own articles.