{"id":1069,"date":"2012-09-19T15:21:59","date_gmt":"2012-09-19T12:21:59","guid":{"rendered":"http:\/\/unitycoder.com\/blog\/?p=1069"},"modified":"2012-09-22T02:27:23","modified_gmt":"2012-09-21T23:27:23","slug":"testing-mecanim-biped","status":"publish","type":"post","link":"https:\/\/unitycoder.com\/blog\/2012\/09\/19\/testing-mecanim-biped\/","title":{"rendered":"Testing Mecanim + Biped"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1070\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/09\/19\/testing-mecanim-biped\/mecanim_biped_unity4\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_biped_unity4.jpg?fit=680%2C465&amp;ssl=1\" data-orig-size=\"680,465\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"mecanim_biped_unity4\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_biped_unity4.jpg?fit=300%2C205&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_biped_unity4.jpg?fit=680%2C465&amp;ssl=1\" class=\"alignnone size-full wp-image-1070\" title=\"mecanim_biped_unity4\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_biped_unity4.jpg?resize=680%2C465\" alt=\"\" width=\"680\" height=\"465\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_biped_unity4.jpg?w=680&amp;ssl=1 680w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_biped_unity4.jpg?resize=300%2C205&amp;ssl=1 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/p>\n<p>Tried to follow the mecanim tutorial from here: <a title=\"http:\/\/www.youtube.com\/watch?v=QGXns8GemU0\" href=\"http:\/\/www.youtube.com\/watch?v=QGXns8GemU0\" target=\"_blank\">http:\/\/www.youtube.com\/watch?v=QGXns8GemU0<\/a> (Unity 4 &#8211; Using Mecanim)<\/p>\n<p>Had to do few things differently to make it work..(also the current UI seems to be different from that video?)<\/p>\n<p>Here&#8217;s the (modified)\u00a0 steps from the video to get your own biped up &amp; running<\/p>\n<p><strong>Mecanim Biped Guy + Movement Script<\/strong><\/p>\n<ol>\n<li>*Create Biped in Max *Skin it (I used some ready skinned character)<\/li>\n<li>Export to unity as fbx<\/li>\n<li>Select the model in unity project window<\/li>\n<li>Inspector, [x] Create Avatar<\/li>\n<li>*Import the whole movement animations \u00a0folder from the mecanim tutorial <a href=\"http:\/\/netstorage.unity3d.com\/unity\/MecanimSampleBeta7.zip\">http:\/\/netstorage.unity3d.com\/unity\/MecanimSampleBeta7.zip<\/a><\/li>\n<li>Create Animation Controller (in project window)<\/li>\n<li>Assign it to your guy<\/li>\n<li>Show\/Open Controller tab<\/li>\n<li>Drag &amp; drop \u201cIdle\u201d from those imported animations to the controller stage (Animations\/Idles\/Idle)\n<ol>\n<li>Its highlighted in orange, so it\u2019s the default clip<\/li>\n<\/ol>\n<\/li>\n<li>Right click: Create state &gt; From new blend tree<\/li>\n<li>Rename it to \u201cRuns\u201d<\/li>\n<li>Double click it (Blend Tree)<\/li>\n<li>*Note: Top of the controller tab,\u00a0 you have: Base Layer &gt; Blend Tree (click \u201cBase Layer\u201d to get back to root)<\/li>\n<li>Select your blendtree<\/li>\n<li>Inspector: Press + (Add Motion Field)\n<ol>\n<li>Add: RunLeft<\/li>\n<li>Add: Run<\/li>\n<li>Add: RunRight<\/li>\n<\/ol>\n<\/li>\n<li>*Note: If you restart unity in between, its not easy to get back to editing the controller..(?)<\/li>\n<li>To see preview: Select your Blend tree from stage, inspector has preview window at bottom\n<ol>\n<li>Press play at the inspector preview window, your guy starts running<\/li>\n<li>You can drag the Blend parameter, to blend between the 3 different runs<\/li>\n<\/ol>\n<\/li>\n<li>Go back to base layer<\/li>\n<li>Right click on top of \u201cidle\u201d, select Create Transition\n<ol>\n<li>Connect\/drag the line to runs<\/li>\n<\/ol>\n<\/li>\n<li>Right click on top of \u201cruns\u201d, select Create Transition\n<ol>\n<li>Connect\/drag the line to idle<\/li>\n<\/ol>\n<\/li>\n<li>Add events (press +)\n<ol>\n<li>Speed (float)<\/li>\n<li>Direction (float)<\/li>\n<li>Jump (Boolean)<\/li>\n<\/ol>\n<\/li>\n<li>Select the arrow going from \u201cidle\u201d to \u201cruns\u201d\n<ol>\n<li>In inspector, you see conditions (different from tutorial video)<\/li>\n<li>Make condition: Greater : Speed : 0.1 (that means, we go to \u201cRuns\u201d, if speed value is greater than 0.1)<\/li>\n<\/ol>\n<\/li>\n<li>Select the arrow going from \u201cruns\u201d to \u201cidle\u201d\n<ol>\n<li>Make condition: Less : Speed : 0.1 (that means, we go to \u201cidle\u201d, if speed value is less than 0.1)<\/li>\n<\/ol>\n<\/li>\n<li>Drag the Jump in to stage\n<ol>\n<li>from Animations \/ Jump \/ Jump<\/li>\n<\/ol>\n<\/li>\n<li>Create Transitions between Jump &amp; Runs (to &amp; back)\n<ol>\n<li>Select transition line from \u201cruns\u201d to \u201cjump\u201d<\/li>\n<li>Make condition to: If | Jump (that means, if jump == true, we go to jump)<\/li>\n<li>Select transition line \u00a0from \u201cjump\u201d to \u201cruns\u201d<\/li>\n<li>Keep default condition: Exit Time : \u2026 (it means, at the last 10% of the animation time, we start to go back to other \u201cruns\u201d)<\/li>\n<\/ol>\n<\/li>\n<li>Add this script to our guy in scene (for movement)\n<ol>\n<li>AvatarCtrl.cs (script below)<\/li>\n<\/ol>\n<\/li>\n<li>Select your camera\n<ol>\n<li>Add SmoothFollow script<\/li>\n<li>Assign your guy as follow target<\/li>\n<\/ol>\n<\/li>\n<li>Test it<\/li>\n<li>problem: its running on wrong directions..<\/li>\n<li>fix: Select blend tree\n<ol>\n<li>Set dropdown parameter: Direction (it was speed?)<\/li>\n<li>Uncheck [x] Automate thresholds<\/li>\n<li>for runleft: -1<\/li>\n<li>for: run: 0<\/li>\n<li>for: runright: 1<\/li>\n<li>check [x] Automate thresholds again<\/li>\n<li>Because GetAxis returns (-1 to 1)<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><strong>PROBLEMS:<\/strong><\/p>\n<p>&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 For some reason, my biped is normal size in editor, but in play mode it explodes to 100m size..\u00a0\u00a0 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..<\/p>\n<p>&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 At first it was running in strange directions, had to do that threshold setting manually..<\/p>\n<p>&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 In the preview window, I didn\u2019t see the animations using my biped..<\/p>\n<p>&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Theres some large values visible on the blend window for direction.. eventhough automatic thresholds are on?<\/p>\n<p><strong>&#8212; AvatarCtrl.cs &#8212;<\/strong><\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">using UnityEngine;\r\nusing System.Collections;\r\npublic class AvatarCtrl : MonoBehaviour {\r\nprotected Animator animator;\r\npublic float DirectionDampTime = 0.25f;\r\nvoid Start () {\r\nanimator = GetComponent&lt;Animator&gt;();\r\n}\r\nvoid Update () {\r\nanimator.SetBool(&quot;Jump&quot;, Input.GetButton(&quot;Fire1&quot;) );\r\nfloat h = Input.GetAxis(&quot;Horizontal&quot;);\r\nfloat v = Input.GetAxis(&quot;Vertical&quot;);\r\nanimator.SetFloat(&quot;Speed&quot;, h*h+v*v);\r\nanimator.SetFloat(&quot;Direction&quot;, h, DirectionDampTime, Time.deltaTime);\r\n}\r\n}\r\n<\/pre>\n<p>&#8212;<\/p>\n<p>Some images of broken biped imports.. (character looks fine in editor, but once you hit play it explodes..)<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors3.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1086\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/09\/19\/testing-mecanim-biped\/mecanim_errors3\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors3.jpg?fit=600%2C551&amp;ssl=1\" data-orig-size=\"600,551\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"mecanim_errors3\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors3.jpg?fit=300%2C275&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors3.jpg?fit=600%2C551&amp;ssl=1\" class=\"alignnone size-medium wp-image-1086\" title=\"mecanim_errors3\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors3-300x275.jpg?resize=300%2C275\" alt=\"\" width=\"300\" height=\"275\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors3.jpg?resize=300%2C275&amp;ssl=1 300w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors3.jpg?w=600&amp;ssl=1 600w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\n<a href=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors1.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1088\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/09\/19\/testing-mecanim-biped\/mecanim_errors1\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors1.jpg?fit=352%2C500&amp;ssl=1\" data-orig-size=\"352,500\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"mecanim_errors1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors1.jpg?fit=211%2C300&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors1.jpg?fit=352%2C500&amp;ssl=1\" class=\"alignnone size-medium wp-image-1088\" title=\"mecanim_errors1\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors1-211x300.jpg?resize=211%2C300\" alt=\"\" width=\"211\" height=\"300\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors1.jpg?resize=211%2C300&amp;ssl=1 211w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors1.jpg?w=352&amp;ssl=1 352w\" sizes=\"auto, (max-width: 211px) 100vw, 211px\" \/><\/a><br \/>\n<a href=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors2.jpg\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1087\" data-permalink=\"https:\/\/unitycoder.com\/blog\/2012\/09\/19\/testing-mecanim-biped\/mecanim_errors2\/\" data-orig-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors2.jpg?fit=500%2C415&amp;ssl=1\" data-orig-size=\"500,415\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"mecanim_errors2\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors2.jpg?fit=300%2C249&amp;ssl=1\" data-large-file=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors2.jpg?fit=500%2C415&amp;ssl=1\" class=\"alignnone size-medium wp-image-1087\" title=\"mecanim_errors2\" src=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors2-300x249.jpg?resize=300%2C249\" alt=\"\" width=\"300\" height=\"249\" srcset=\"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors2.jpg?resize=300%2C249&amp;ssl=1 300w, https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_errors2.jpg?w=500&amp;ssl=1 500w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tried to follow the mecanim tutorial from here: http:\/\/www.youtube.com\/watch?v=QGXns8GemU0 (Unity 4 &#8211; Using Mecanim) Had to do few things differently to make it work..(also the current UI seems to be different from that video?) Here&#8217;s the (modified)\u00a0 steps from the video to get your own [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1070,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,3],"tags":[27,305,306,308,304,307],"class_list":["post-1069","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-demos","category-unity3d","tag-3ds-max","tag-biped","tag-character","tag-fbx","tag-mecanim","tag-unity4"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/unitycoder.com\/blog\/wp-content\/uploads\/2012\/09\/mecanim_biped_unity4.jpg?fit=680%2C465&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/p1KTaT-hf","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/comments?post=1069"}],"version-history":[{"count":15,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1069\/revisions"}],"predecessor-version":[{"id":1080,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/posts\/1069\/revisions\/1080"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media\/1070"}],"wp:attachment":[{"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/media?parent=1069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/categories?post=1069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitycoder.com\/blog\/wp-json\/wp\/v2\/tags?post=1069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}