animation controller, parameters, conditions

In this article we will continue to manage a 3D character in the Unity environment. Last time we focused on porting animations; they were added without materials (textures). To display textures from the original blender model, click on one of the animations, for example, idle.fbxin the right window select the tab Materials. In the combobox Material Creation Mode let's choose Standard (Legacy), Location Use External Materials (Legacy)leave the remaining fields unchanged, click the button Apply. Now our animation displays the original skin of the model.

Character skin import options

Character skin import options

In addition, let's go to the tab Rig and change the value of the combobox Animation Type With Generic on Humanoidapply this by clicking Apply. Button Configure… allows you to check and adjust the correspondence of skeleton bones in the blender model and in Unity, this is discussed in detail in this post. These steps must be repeated for all three animations.

New system "humanoid" animations

New “humanoid” animation system

After changing the animation type from Generic on Humanoid in the tab Animation set the animation to loop (checkbox Loop Time) and repetition of the pose (checkbox Loop Pose). Let's leave the default root object transformation settings: rotation (root rotation transform) – Body Orientationvertical position (root rotation transform(y)) – Originalhorizontal position (root rotation transform(xz)) – Center of Mass. The color of the corresponding “light bulbs” loop match indicates the correspondence between the beginning and last frame of the animation.

These animation options are only available for Animation Type Humanoid

These animation options are only available for Animation Type Humanoid

Let's move the animation idle V Hierarchyrename the new one GameObject V Player.

New Player

New Player

Now let's create an animation manager Animator Controllerwhich will manage the transitions between our animations, transitions between states finite state machine (FSM) character. A finite state machine is a mathematical model that represents the “working process” of a certain complex mechanism in the form of transitions between a finite set of states.

States of our state machine

States of our state machine

Let's create Animator Controller in the folder with animations (Assets/Animations): press the right mouse button, select Create->Animator Controllerlet's rename it to manager. Double-click on our animation manager, drag our three animations into the link editor, adding names along the way.

idle, walk, run

idle, walk, run

The default animation into which our character ends up after the start is marked in orange. To make another animation the starting one, you need to right-click on the corresponding animation and select from the drop-down menu Set As Layer Default State. Let's create a transition from animation idle V walk. To do this, right-click on the state idleselect from the drop-down list Make Transition and bring the arrow to the state walk. You can zoom in and out of the diagram of transitions between states by scrolling the mouse wheel, and change the view by moving the mouse while holding down the middle key.

Let's make the transition arrow active (transition). To transition from one animation state to another, formalized conditions are used (conditions). Conditions interact with parameters (parameters). Let's go to the subtab Parameters window Animator. Let's add a new parameter (click on the sign +) type float With name speed. Let's add the following condition: if the speed value is greater than 0.1, we move from the state idle V walk. To do this, click + in the right tab Conditions V Inspectorselect the parameter speedcondition “greater than” (Greater), value 0.1. If you leave the checkbox Has Exit Time enabled for all transitions, before changing the animation, for example, from idle to walk, a pause will appear due to the fact that the controller will bring the animation cycle to the end and only then switch the state. Let's remove this checkbox so that switching occurs immediately after changing the parameter, later, immediately after pressing the corresponding control key.

Don't forget to uncheck the Has Exit Time checkbox.

Don't forget to uncheck the Has Exit Time checkbox.

Let's add a reverse transition from the state walk V idleif parameter speed becomes less than 0.1. To transition from state idle in a state run we will add a parameter running type bool. If the flag running becomes trueswitch to state run, and vice versa. Let's add two corresponding transitions. An animation diagram with all the described transitions should look something like this.

State machine states in Unity

State machine states in Unity

State machines with transitions are described in the following table.

Transition

Condition

idle-walk

speed > 0.1

walk-idle

speed < 0.1

idle-run

running = true

run-idle

running = false

Bind the animation controller to the game object playerdrag manager in field Controller component Animator. Leave the checkbox Apply Root Motion without changes, selected, since we will use the movement of the game object around the scene with the playback of animations.

player and manager

player and manager

Let's position the tab Animator in the environment so that you can change animation parameters and see how it affects the character. I moved the camera so that we saw the character from the back, in the style third person shooter. Let's start the game by pressing the button play.

Visual control of animations

Visual control of animations

Let's stop there today. The next article will be about controlling the character and camera using a proprietary plugin PlaymakerIn subsequent ones – about controlling the character and the camera without Playmaker.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *