Mecanim Unity 4 Tutorial (step-by-step from the video)


While looking at the new mecanim tutorial video, wrote down the steps from it (not finished yet)
(huh – thats a lot of clicks just to get your robot moving.. certainly could use some helper scripts/plugins to do most of the stuff automagically)

Video from Unity (tutorial scene download is there also)

Tutorial steps

  1. Open Tutorial Start
  2. Pick Robot prefab
  3. Animations tab
  4. Uncheck [ ] Import animations
  5. Rig tab
  6. Animation type: Humanoid
  7. Apply
  8. Configure
  9. Configure Avatar
  10. Mapping : Automap
  11. (Some bones are red, because mecanim wants T-pose)
  12. Pose: Enforce T-Pose
  13. Muscles tab
  14. Prompts for Apply (apply)
  15. (We can apply constraints to different parts of the body, but no need to do now)
  16. Press Done
  17. Drag & Drop the robot prefab to scene (hierarchy)
  18. (Scene uses light probes, need to set robot mesh renderer to use them)
  19. Select Robot in scene
  20. Select Robot2 under it
  21. Check [x] Use light probes in the skinned mesh renderer
  22. Select Animations/Walk forward
  23. Go to animations tab
  24. Click clips/Walk forward
  25. (You can then preview your animations (if they have baked mesh) or create loopable clips)
  26. Select robot in scene
  27. (it has component animator)
  28. Window / Animator
  29. Select tutorial folder
  30. Right click > Create Animation Controller
  31. Name it MyBotControl
  32. Drag & drop it to your robot, Animator / Controller
  33. Check [x] animate physics
  34. Go to animations folder
  35. Pick Idles
  36. Click Idle (under clips)
  37. See preview (press preview play button)
  38. Pick Animations/Idles/Idle (with play button icon)
  39. Drag & drop it to Animator window (creates orange box *Orange is the default clip)
  40. Press Play to test the scene
  41. (Your robot now has the idle animation)
  42. Right click on Animator window, select Create state / From new blend tree
  43. Rename it as “WalkBack”
  44. Double click to enter it
  45. (From animator top left you can go back to parent, by clicking base layer, but not yet)
  46. Click + Button on inspector 3 times (for blend tree)
  47. Drag & drop Animations / WalkBack / WalkBack clip to middle motion field that we just created
  48. Do the same for “WalkBackTurnLeft” (drop it to first motionfield)
  49. Do the same for “WalkBackTurnRight” (drop it to 2rd motionfield)
  50. ** error : pressed some keys, whole animator went empty.. also couldn’t go inside WalkBack anymore, had to re-do it.. **
  51. Add parameter: Speed                 (keep capital letter)
  52. Add parameter: Direction             (keep capital letter)
  53. Select walkback blendtree
  54. On Inspector set Parameter dropdown to Direction (it was Speed)
  55. Set start range to: -1 (because unity input systems returns values from -1 to 1), by clicking the number 0 under the blue curves
  56. Go back to base layer (clicking the “Base layer>” on topleft in animator window)
  57. Create transition from Idle to WalkBack, right click on Idle, Select Make transition, Drag the line to WalkBack, click.
  58. Click to select the transition line (we set condition that when should be do transition)
  59. Set conditions: Speed | Less | -0.1
  60. Create transition from WalkBack to Idle, right click on WalkBack, Select Make transition, Drag the line to Idle, click.
  61. Click to select the transition line (we set condition that when should be do transition)
  62. Set conditions: Speed | Greater | -0.1
  63. Go inside WalkBack blendtree, you can preview the direction value by dragging it on the blendtree
  64. Note. You can also drag & drop any avatar enabled character to the preview window, to use it as a preview
  65. Select robot in scene
  66. Drag & Drop “BotControlScript” to the robot
  67. Open the script (double click)
  68. Line 48: horizontal & vertical get values from GetAxis()
  69. SetFloat() sends the values to animator
  70. (Back to unity)
  71. Set Robot rigidbody mass to: 60
  72. Freeze rigidbody rotation for all: XYZ
  73. Capsule collider: Set Center to Y:1, Height: 2, Radius: 0.3
  74. (Press play to test)
  75. ** had some error here, robot is not moving as it should: Transition line from Idle to Walkback was not set “Condition: Speed | Less | -0.1” **
  76. (Video at 14:37 – Walk and Run : using Nested Blend Trees)
  77. Go to Animator, Base Layer
  78. Right click on stage: Create State / From new blend tree
  79. Rename it as “Locomotion”
  80. Enter the blend tree (double click)
  81. In inspector click + button: “New Blend Tree” (And rename it as “Walks”)
  82. In inspector click + button: “New Blend Tree” (And rename it as “Runs”)
  83. Select upper blend tree “Walks”
  84. Add 3 motion fields (+ button “Add Motion Field”)
  85. Expand Animations / WalkForward motion clip in Project window
  86. Drag & Drop “WalkForward” clip to the middle motion field
  87. Expand Animations / WalkForwardTurns motion clip in Project window
  88. Drag & Drop “WalkFwdTurnLeft”-clip to top motion field
  89. Drag & Drop “WalkFwdTurnRight”-clip to bottom motion field
  90. (you can pan the animator stage with middle mouse button down, or with alt+left mouse down)
  91. Select the blend tree “Runs”
  92. Set the range start to: -1 (like we did before @step 55)
  93. On Inspector set Parameter dropdown to Direction (it was Speed)
  94. Now select the lower blend tree (that we created @step 82)
  95. Add 3 motion fields (+ button “Add Motion Field”)
  96. (Lets look how these clips were created)
  97. (if you select Runs (blue icon), and then select any of the clips listed, you can preview the loops)
  98. ** Note: Some bug in the preview window: character disappears **
  99. (Lets remove Run clip, press minus under it)
  100.  (This fbx has several animations inside)
  101. (Add new clip, press plus)
  102. (select the just added clip)
  103. (Source take: Run, this will also rename your clip to Run)
  104. (if you press Play on preview window, you’ll see its not perfectly looped)
  105. (You need to drag the Start & End markers on the timeline to create loop)
  106. (Lets put start to 302 & End to 319 – Drag end marker to 302, then keep dragging forward until the loop is complete – “Traffic lights” are also green then)
  107. (Check [x] the Loop pose)
  108. (Try playing preview)
  109. (Check [x] Bake into Pose under Root transform position (Y))
  110. (If you check preview you’ll see that the guy is not running in straight line)
  111. (You can see in the text “Average velocity is -0.059, 0.000, 5.305”, it should have “0” in X&Y)
  112. (Under Root Transform Rotation drag the offset value, until your Average Velocity is correct – Set it to “-0.64”)
  113. (Click Apply at the bottom.. scroll the inspector if its not visible)
  114. (Check preview, not its running straight line)
  115. Expand Animations / Runs motion clip in Project window
  116. Drag & Drop “RunLeft”-clip to top motion field
  117. Drag & Drop “Run”-clip to top motion field
  118. Drag & Drop “RunRight”-clip to top motion field
  119. Set the lower threshold start to: -1 (like we did before)
  120. On Inspector set Parameter dropdown to Direction (it was Speed)
  121. (we are now at 21:00 in the video) be continued..

7 Comments + Add Comment

Leave a comment


Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.