Made With Unity | New Animation For Ready Player Me Avatar

Rehtse Studio
8 min readDec 13, 2023

--

My latest video covered how to incorporate a Ready Player Me Avatar into Unity’s Starter Assets Third Person Character Controller Package, make the avatar work on Desktop and Mobile environments, and add the tools needed to complete the process.

In this article, we will use the same project to continue adding new animations to our Avatar using animations from Mixamo and make it usable on both Desktop and Mobile.

Three Crucial Script

We must dissect three scripts: ThirdPersonController.cs, StarterAssetsInput.cs, and UICanvasControllerInput.cs.

ThirdPersonController.cs Script

Like the name intel, the ThirdPersonController.cs controls your Avatar and uses the Input from Keyboard or Gamepad to move your character and call for the animation.

Part of the behavior is located on the Move() method on the script; if your script has not been edited, the method is located on line 214. In this method, the input is being read, and depending on the speed and what input has been used is the animation it will play and the speed at which my Avatar will move.

Method JumpAndGravity() is self-explanatory; it will check if you are jumping, add the necessary calculations to add gravity and play the jump animation.

StarterAssetsInput.cs Script

This script is your middleman to read your inputs from the keyboard, mouse, or gamepad from Unity’s New Input System and the Player Input component.

UICanvasControllerInput.cs Script

For a short script, its goal is to translate your UI Canvas Input from your mobile to be read by the StarterAssetsInput.cs script.

Our ThirdPersonController.cs and StarterAssetsInput.cs are in the PlayerArmature GameObject or on your Ready Player Me Avatar from the last video on the Hierarchy window.

UICanvasControllerInput.cs is located on the UI_Canvas_StarterAssetsInputs_Joysticks Game Object.

New Animations With Mixamo

Downloading Animations

On Mixamo, we will use two crouch animations: Crouch Idle and Crouch Walking.

Type “Crouch” on the search bar and select Crouching Idle; you will see the animation playing on your right side. For the walk, the animation is called Crouched Walking.

For both animation clips, press Download on the right side of the screen. A new window will be opened; use the picture values for the DOWNLOAD SETTINGS window, press Download, and save the animation in Unity’s folder. I recommend creating a folder called Animations.

Adding The Animations

We are in the tidies part when adding animation from Mixamo. If we like to edit the animation and loop the clip when using it, we must do the following first.

Select Rig->Animation Type->Humanoid for both animation and press Apply.

Please select the animation clips with a triangle icon next to the name and press CTRL + D.

This will duplicate the clip and add it to your Animations folder, and from there, you can check Loop Time. Using the image, edit the following settings for both animations.

Find your StarterAssetsThirdPerson animator controller.

We will create a new parameter and Blend Tree on the Animator window to add our Crouch animation.

We will include a new Bool Parameter called Crouch.

On the animator, right-click and select Create State->From New Blend Tree, named the blend tree Crouch Blend Tree.

Rick-clicks on Idle Walk Run Blend, Make Transition and drag it to Crouch Blend Tree. Please do it again from Crouch Blend Tree to Idle Walk Run Blend.

Select the white transition from Idle Walk Run Blend to Crouch Blend Tree, and on the Conditions, from the dropdown list, select Crouch and True.

The white transition from Crouch Blend Tree to Idle Walk Run Blend set Crouch to false.

Double click Crouch Blend Tree, and for Parameter, we use Speed.

We press the plus sign on the Motion, select Add Motion Field, and add the two crouch animations, ensuring the Crouching Idle is the first.

Reading The Crouching Input

Before editing the three scripts we discussed earlier, we must create the crouch input and from what key press will be read.

StarterAssets

Locate the Input Action Asset called StarterAssets and double-click it.

Since our crouch input will behave similarly to the Sprint input, only use it when pressing the button, right-click on Sprint Action, and select Duplicate.

Rename the new Action to Crouch and edit the input keys on the Binding Properties, find the Path for the Left Control [Keyboard] and Left Shoulder [GamePad]

StarterAssetsInputs.cs

On the StarterAssetsInputs.cs, we will create a new bool variable called crouch and a few new methods.

Where the other public variables are located, add public bool crouch.

Under the public void SprintInput() method, create a new method called public void CrouchInput() and add the following from the image.

Under the OnSprint() method, add the public void OnCrouch() method.

ThirdPersonController.cs

On the ThirdPersonController.cs, we are adding a new variable where all the other int variables are located.

Named the new variable private int _animIDCrouch.

We will add the new variable to the following spots:

On the AssignAnimationIDs() method

Inside the Move() method, on the if(_hasAnimator) statement

We will add another parameter to be considered inside our JumpAndGravity() method in the if(Grounded) statement.

UICanvasControllerInput.cs

We are just going to add one method on UICanvasControllerInput.cs, VirtualCrouchInput().

Almost Done

With everything we have now, we can hit play and test it on the Desktop, but to finish off with flying colors, we are going to edit UI_Canvas_StarterAssetsInputs_Joysticks GameObject to add a new button for our Crouch input.

We will duplicate UI_Virtual_Button_Sprint and rename it UI_Virtual_Button_Crouch.

While selecting the GameObject, please change the Image to any color and move it to where you want the button to be.

Now, we edit the UI Virtual Button component and make it use the method we created called VirtualCrouchInput.

PRESS PLAY

The crouch animation will play while moving forward or not moving at all by pressing the Left CTRL or the new UI button.

In Conclusion

We added new animations to our Ready Player Me avatar using free animation from Mixamo and did easy edits to scripts and components to accept new inputs to the project.

🎮To Be Continued 🎮

--

--

Rehtse Studio

Game Developer sharing content around Unity, programing and tips and tricks in game dev.