Sep
19
2012

Testing Mecanim + Biped

Tried to follow the mecanim tutorial from here: http://www.youtube.com/watch?v=QGXns8GemU0 (Unity 4 – Using Mecanim)

Had to do few things differently to make it work..(also the current UI seems to be different from that video?)

Here’s the (modified)  steps from the video to get your own biped up & running

Mecanim Biped Guy + Movement Script

  1. *Create Biped in Max *Skin it (I used some ready skinned character)
  2. Export to unity as fbx
  3. Select the model in unity project window
  4. Inspector, [x] Create Avatar
  5. *Import the whole movement animations  folder from the mecanim tutorial http://netstorage.unity3d.com/unity/MecanimSampleBeta7.zip
  6. Create Animation Controller (in project window)
  7. Assign it to your guy
  8. Show/Open Controller tab
  9. Drag & drop “Idle” from those imported animations to the controller stage (Animations/Idles/Idle)
    1. Its highlighted in orange, so it’s the default clip
  10. Right click: Create state > From new blend tree
  11. Rename it to “Runs”
  12. Double click it (Blend Tree)
  13. *Note: Top of the controller tab,  you have: Base Layer > Blend Tree (click “Base Layer” to get back to root)
  14. Select your blendtree
  15. Inspector: Press + (Add Motion Field)
    1. Add: RunLeft
    2. Add: Run
    3. Add: RunRight
  16. *Note: If you restart unity in between, its not easy to get back to editing the controller..(?)
  17. To see preview: Select your Blend tree from stage, inspector has preview window at bottom
    1. Press play at the inspector preview window, your guy starts running
    2. You can drag the Blend parameter, to blend between the 3 different runs
  18. Go back to base layer
  19. Right click on top of “idle”, select Create Transition
    1. Connect/drag the line to runs
  20. Right click on top of “runs”, select Create Transition
    1. Connect/drag the line to idle
  21. Add events (press +)
    1. Speed (float)
    2. Direction (float)
    3. Jump (Boolean)
  22. Select the arrow going from “idle” to “runs”
    1. In inspector, you see conditions (different from tutorial video)
    2. Make condition: Greater : Speed : 0.1 (that means, we go to “Runs”, if speed value is greater than 0.1)
  23. Select the arrow going from “runs” to “idle”
    1. Make condition: Less : Speed : 0.1 (that means, we go to “idle”, if speed value is less than 0.1)
  24. Drag the Jump in to stage
    1. from Animations / Jump / Jump
  25. Create Transitions between Jump & Runs (to & back)
    1. Select transition line from “runs” to “jump”
    2. Make condition to: If | Jump (that means, if jump == true, we go to jump)
    3. Select transition line  from “jump” to “runs”
    4. Keep default condition: Exit Time : … (it means, at the last 10% of the animation time, we start to go back to other “runs”)
  26. Add this script to our guy in scene (for movement)
    1. AvatarCtrl.cs (script below)
  27. Select your camera
    1. Add SmoothFollow script
    2. Assign your guy as follow target
  28. Test it
  29. problem: its running on wrong directions..
  30. fix: Select blend tree
    1. Set dropdown parameter: Direction (it was speed?)
    2. Uncheck [x] Automate thresholds
    3. for runleft: -1
    4. for: run: 0
    5. for: runright: 1
    6. check [x] Automate thresholds again
    7. Because GetAxis returns (-1 to 1)

PROBLEMS:

–          For some reason, my biped is normal size in editor, but in play mode it explodes to 100m size..   Solved: Had to set model import scale to default 0.01 (instead of 0.001), but the model is 100 meters tall.. I guess need to scale it ready on 3D software..

–          At first it was running in strange directions, had to do that threshold setting manually..

–          In the preview window, I didn’t see the animations using my biped..

–          Theres some large values visible on the blend window for direction.. eventhough automatic thresholds are on?

— AvatarCtrl.cs —

using UnityEngine;
using System.Collections;
public class AvatarCtrl : MonoBehaviour {
protected Animator animator;
public float DirectionDampTime = 0.25f;
void Start () {
animator = GetComponent<Animator>();
}
void Update () {
animator.SetBool("Jump", Input.GetButton("Fire1") );
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
animator.SetFloat("Speed", h*h+v*v);
animator.SetFloat("Direction", h, DirectionDampTime, Time.deltaTime);
}
}

Some images of broken biped imports.. (character looks fine in editor, but once you hit play it explodes..)




4 Comments + Add Comment

  • “For some reason, my biped is normal size in editor, but in play mode it explodes to 100m size.. Solved: Had to set model import scale to default 0.01 (instead of 0.001), but the model is 100 meters tall.. I guess need to scale it ready on 3D software..”

    I struggled with this for a long time and after desperately trying to scale Max’s bipeds using voodoo and what not, i discovered you can avoid this problem in Unity by just reconfiguring your avatar after changing the import scale. You’ll have to reset the pose and (just in case) mapping, then hit apply and done.

    • Thanks! I’ll try that :) (I did try to press just about every button last time, maybe it has been improved for the current version)

  • Thanks!! It works for me. Now I have my own biped character rigged with skin in 3ds max runnig and jumping in Unity without make any animation. It´s a dream.

  • Some info here also:
    “we do not support all the roll bone configuration from biped. If possible re-parent your roll bone, like Bip001 R ForeTwist should be under Bip001 R ForeArm. ”
    http://forum.unity3d.com/threads/184827-Mecanim-3ds-Max-Studio

Leave a comment

@unitycoder_com

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