Search Unity

Strange axis behavior for Generic animation - Good rotation axis, yet wrong movement axis

Discussion in 'Animation' started by Max_Bol, Oct 16, 2014.

  1. Max_Bol

    Max_Bol

    Joined:
    May 12, 2014
    Posts:
    168
    I have this strange issue which involve the known Y-up and Z-up that affect those who uses 3ds Max for their animation.

    I'm currently working on a quadruped robot which is animated with a custom CatRig inside of 3ds Max and import it as a Generic animation
    I already knew about the problem that comes with axis switch the goes from 3ds Max to Unity which require the animation to be done in a 90 degree inside 3ds Max. (otherwise, the animation will be faced upward inside of Unity)

    So I did the necessary change and all so that the animation is facing in the right direction. Not only the animation work correctly, but also mix perfectly inside with the Animator's blend tree.

    Now, there is a strange problem with the movement of the Root Node. Strangely, the X,Y,Z axis of the Root Node movement (for example, moving the mesh forward, higher during jump, etc.) is actually in the wrong direction. It's as if the -90 on X necessary in 3ds Max for the orientation is not needed for the Root Node translation but instead is necessary on the Z axis.


    The left image (3dsMax) show that the robot is oriented toward the Z as it should and as the right (Unity) show, it's oriented toward the right face. The orange arrow show the direction which the Root Node (so the whole thing) moves toward. In case some wonder, in the right image (3dsMax), the rotations of the master (Root Node) is at its origin (0,0,0) so the problem is not something as simple as a ResetXForm or rotating the Root Node pivot point. Doing so would only rotate the right image (Unity) toward the wrong direction.

    The only way of fixing this problem which I have found by tries & errors is the following :
    - First, I must apply a 90,0,90 rotation on the Root Node(dummy) so that, inside 3dsMax, I actually see the animated character (robot in this case) in the right direction. It's then easier to animate its translation correctly. (ONLY for the root node, it seems like the Front/Back is X, Up is Z and Sides is Y)
    While I apply this 90,0,90, it's only a temporary thing so I only do it with the basic "Select&Rotate" tool. (In other words, it keeps it rotation origin intact)
    - I animate the Root Node for every animation movement based on the needs.
    - Once it's done, I have to remove the 90,0,90 from the Root Node (in other words, return it to its rotation origin). For some strange reason, not doing it will make the animations on both X&Y (inside of 3dsMax) to be always in toward the same direction inside of Unity. (yeah... imagine that both the strafe and forward animation move toward the SAME axis in Unity, Strange isn't it?)
    - Once the Root Node (Dummy) rotation inside 3ds Max is returned to 0,0,0, the animation will be played in a strange way (since the mesh is pointing upward on Z, yet it's moving like if it was pointing toward X.) inside of 3ds Max, but will be played correctly inside of Unity.

    Now, I wish to make sure that what I do isn't just a useless work-around since this is quite strange behavior which add to the workflow and risk of useless error. I did tried to add another dummy parent to see the behavior, but seems like it only add more unwanted Axis problems. (Like having the Y translation affecting both Y and Z inside of Unity. Crappy things like that.)
     
  2. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Interesting post. Thank you!

    I've only recently tried using Mecanim generic rig in combination with 3ds Max, to see if it's any good for production work. It seems to be really unpredictable combination and does not seem to work as one would expect.
    I've only done 1 or 2 tests with generic rig, and I run into problem of root node not transforming properly.

    Known Y-up and Z-up issue
    Also, I'm not sure if this Z / Y up issue is so well known, in sense that based on what I've read there seems to be no clear solution to this that works from start to finish, or I haven't just found it, let alone solved it myself. In addition to this, Unity manual or Unity devs don't seem to have any posts about this topic either.

    It would be interesting to see your setup more closely, your 3ds Max image does not contain all the information, screen capture with world axis and model orientation during animation and export would be really interesting to see.
    I'm not sure if I understood your explanation correctly, what your models animation up direction is, and how you export your setup.

    I'll do my own tests and post my findings.
     
  3. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Hey guys I also use Max exclusively and I have not had this problem at all.
    In max make sure your character is facing toward you in the front viewport and make sure your root bone is oriented Y facing up, Z positive forward, when exporting as fbx make sure Axis conversion is set to Y-up.

    One factor that may be different is I use fbx 2012 export. May consider installing the 2012 fbx exporter.
     
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    theANMATOR2b:
    Thanks for the tip; initial testing with your setup - basic stuff seems to be working OK.

    I think your rotations are in 3ds Max [90,0,-90] or matrix3 [0,-1,0] [0,0,1] [-1,0,0] [0,0,0] - if I'm correct.

    Although root rig object gets -90/270 x-axis rotation in Unity, it seems like this doesn't cause obvious problems, like I was getting with couple of tests I made (not with all tests however).

    I bet you have done more testing with this setup so I'll do more tests to see how things work for me.

    Thanks again!
     
    theANMATOR2b likes this.
  5. Max_Bol

    Max_Bol

    Joined:
    May 12, 2014
    Posts:
    168
    As you can see inside the screenshot (left), the Y is facing up and the Z is facing forward in 3ds Max.
    (The axis shown is the axis at its origin so that's why the robot is facing up)
    There were "no" modification between the mesh on the left (3ds Max) and right (Unity) except for being exported.

    As I said, the problem is not related to the orientation of the animated mesh, but toward its Root Node translation within the Mecanim system.

    A simple way of explaining the effect to eses is the following :
    - Since I applied the solution for the orientation (Z-Up in 3ds Max toward Y-Up in Unity), the the facing of the FBX is correct in Unity. Since the Mecanim always force the rotation to its origin (0,0,0), this is a must-do. (as the automatic rotation of 270,0,90 done in Unity isn't counted by the Mecanim system)
    - But as soon as I move the Root Node (which is the bone or dummy which is the Parent of EVERYTHING in the mesh. It's also called the Master node if you prefer), the orientation of that single node isn't the same as the rest once inside of Unity.

    As for the FBX exporter with Axis conversion set to Y-up, I tried it as well as with Z-up just in case (one of the first thing I double-checked) and both ways ended up with the same results. My guess is related to the automatic action of Unity that have been build-in so that FBX with specific signature are automatically aligned (270,0,90 or something like that) which affect the Mecanim system in some ways.

    To reproduce this thing, you can do as followed :
    In 3ds Max :
    - Create a pair of legs . (could be as simple as you wish as long as it can walk)
    Note : Make sure that the legs' front is toward Z, and their up is toward Y
    - Put the armature (bones) with a pelvis
    - Skin the mesh with the bones
    - Add a Dummy or a Bone as a Master node and make sure that it's located at the center (0,0,0)
    - Put the Master Node as the parent of every part that doesn't have one (this is so that if you move the Master node, everything follows)
    - Create some keys to animate the legs on the spot. (Moon walk for example)
    - Once the walking animation is done, add some animation keys on the Master Node to apply the forward movement (toward Z in 3ds Max) of the legs and pelvis. (You can rhythm and synchronize the forward movement with the moving legs)
    - Export as a FBX
    In Unity :
    - Import the FBX
    - The animation type as Generic and select the Master Node in the "Root Node" option. (Rig tab)
    - You can give a better name to the animation (instead of Take 1) if you want (in the "Animations" tab)
    - Activate the loop option
    - Press the Play button to preview the animation.

    You'll see that the legs will be facing forward (toward the red line on the ground) walking (moon walk) in the good direction, but they will move upward (toward Y) instead of forward (instead of moving toward the red line).

    I tried it with a couple of different meshes and armature and all end up with this result. This might be related to the automatic adjustment done when Unity import the FBX (the 270,0,90 forced rotation).
     
  6. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790

    Hey Max_Bol did you try the 2012 fbx exporter?
    I'm going to attempt to reproduce this but maybe you can perform a couple more tests as well.
    Two things of note from the procedures that could be causing the incorrect axis direction.
    First "- Add a Dummy or a Bone as a Master node and make sure that it's located at the center (0,0,0)"
    It is important to perform this step correctly. Create the dummy in the front viewport so the dummy's local rotation pivot reads 90.0.0. The local transforms are Y up Z forward X doesn't matter.
    Second I always create characters with the root bone (dummy) at the characters COM (center of mass). Animate this for up/down motion only. Then after finishing all the animations in-place (old school) link the characters root (COM) to a spline circle located at 0.0.0. This spline circle is created in the top viewport but I align the pivot to match the characters root bone. So the circle's local axis is Y up, Z forward. Use this circle to animate the characters locomotion and turning. This circle at 0.0.0 is what is use for root motion in Unity.

    But everything else you detailed we do exactly the same and I do not get the animation in Y problem.

    Maybe it really is the 2012 fbx exporter that just works correctly. I read somewhere this is not a Unity problem but it is a fbx axis conversion problem on export but who really knows.

    Hope you find a solution.