Mecanim Unity 3D for Beginners
- Unity 5 – From Beginner to Pro #39 – Mecanim (1) https://www.youtube.com/watch?v=I4Yr8_TU9SI
- Unity 5 – From Beginner to Pro #40 – Mecanim (2) https://www.youtube.com/watch?v=08qfeGNZbR w
- Unity 5 – From Beginner to Pro #41 – Mecanim (3) https://www.youtube.com/watch?v=VpQO6QUPKLg
001 Mechanim Unity 5
Raw mocap data for mecanim in the asset store
Import everything
- GameObject – 3D Object – plane
- Scale 25, 1, 25
- Drag the avatar into the scene
- 0, 0, 0 position
- Hit F to focus on the character (zooms in)
- Right click in the Project – Assets folder in the Raw Mocap Data Folder
- Create – Animator Controller
- Rename it MyAnimator
- Double Click on the MyAnimator and the Animator for this character opens
ADD ANIMATIONS TO THE ANIMATOR - Go to the Idle folder
- Drag IdleNeutral1 into the animator – This will be the starting point for any character (IDLE)
- Drag the animator onto the character
Next Tutorial https://www.youtube.com/watch?v=08qfeGNZbRw - Select main camera – GameObject – align with view
- Play to test
NEW STATE - Double click on the Animator
- Right click on an empty area and select CREATE STATE – NEW BLEND TREE
- Name it walkingforward
- Double click on the Walkingforward state
- Click the Plus icon.
- Add motion fields
- Select WalkForwardTurnRight_zNtrl_short
- Click the plus sign again
- Select WalkForward_NtrlFaceForward
- Click the plus sign again.
- Select WalkForwardTurnRight_zNtrl_short
- Place check in the mirror box in the motion inspector so your last character will turn to the left instead of the right
- Click to the left of the motion graph and make it -1
- In the lower right window, press play to preview the blend animation.
- You can also move the red slider bar in the motion graphic at the top left
https://www.youtube.com/watch?v=VpQO6QUPKLg
CREATE TRANSITIONS / SCRIPT TRANSITIONS
- Create two variables
- Click on the Parameters Tab
- Click the plus sign
- Select Float
- Rename it Speed
- Click on the plus sign again
- Rename it Direction
CREATE A TRANSITION BETWEEN IDLE AND - Right click over idle
- Make transition
- Drag the line over to the walk state
- Click on the little arrow in the middle of the transition line.
NOW LIST A CONDITION FOR THE TRANSITION TO HAPPEN - Click on the plus sign
- Drop Down and select Speed
- Put 0.1 in the box (speed is greater than 0.1)(this means that the character will be walking forward)
- Look above the graph for the words HAS EXIT TIME
- Uncheck (to disable) If you leave it on, then the animation will transition to another after a few seconds) We want the transition to occur only when it meets the condition.
REPEAT THE PROCESS – MAKE A NEW TRANSITION (from walk forward to idle) - Right click the mouse on the walk forward animation
- Select Make transition
- Drag it to the Idle default (orange) (which is the Idle state) (5:09)
- Click on the transition arrow in the center of the line
- Uncheck Has Exit
- Click the plus sign and select Speed from the dropdown
- Change the condition to LESS than 0.1
NOW DIRECTION - Double click on walk forward
- Click the drop down and select DIRECTION
- In the parameters tab, delete blend (because we’re not going to use it)
- Click on the Base Layer Tab
CREATE NEW C# SCRIPT - Right click – Create C# Script
- Name it PlayerController
- Click into the Scene
- Select the default avatar
- Drag the script into the Avatar’s Inspector
- Double click on the script to add some code to it. This will open MonoDevelop
- We need a reference to our Animator (8:34)
- Under the Public Class Type
- Private Animator
- Call it anim;
private Animator anim; //reference to the animator - Need two float variables, one for speed and one for direction
private float playerDirection; // variable to store direction coordinate values you will
receive from the players input
private float playerSpeed; // variable to store speed coordinates
receive from the players input
NEED TO INITIALIZE THE VARIABLE
- Inside the Start Function type
// Get the reference from the Animator
anim = GetComponent<Animator>( ); //get component from the current gameObject
- UPDATE FUNCTION
This is where the change in states happen
// Get user input
playerDirection = input.GetAxis(“Horizontal”);
playerSpeed = input.GetAxis(“Vertical”);
anim.setFloat(“Direction”, playerDirection);
anim.setFloat(“Speed”, playerSpeed);
- Save
- Go back to unity
- Press Play to Test
- Click the Front Arrow and the character should move