Search Unity

Crouch Animation Moving Model Up and Back with Pivot?

Discussion in 'Animation' started by HeWasAgainstIt, Aug 15, 2019.

  1. HeWasAgainstIt

    HeWasAgainstIt

    Joined:
    Jan 20, 2016
    Posts:
    9
    So I made my first human model in Blender and imported it into Unity, then I got Idle, Walk and Run animations working based on this short tutorial here which sets up the Avatar's T-Pose etc.:


    However when I set it up to enter a kneeling animation on a key press, the model plays the animation but also moves upward and backward so that the model ends up floating above the ground. I've looked at the animation previews in Unity and I can see that what I assume is the Pivot moves back and upwards just like the model does during play.

    Here you can see the model during the Idle animation, and then after going into a Kneel animation:
    char-kneel_hover.png

    Then if I look at the kneeling animation preview within Unity, you can clearly see what I assume is the Pivot begin at (0, 0, 0) and then travel backwards and up during the animation:

    char-kneel_pivot.png

    I can understand why it goes backwards seeing as the model moves backwards, but have no idea why it goes up, except perhaps that the arms rotate upwards. Either way, you can see that it's causing a situation where the player character appears to hover mid-air when kneeling. How can I keep it all on the same vertical plane like it is in Blender?

    I've done some research but it hasn't helped so far and I don't know what to look at next. In Blender, there doesn't seem to be any Origin or anything that corresponds to the location of the Pivot in Unity, so I'm assuming it's something purely related to Unity that can't be fixed via Blender alone (though I may be mistaken).
    I'm using the Root Transform option for the Root Motion setting under Motion; I've tried None and the other options and changed the settings that open up when I select them but I haven't got anything that's come close to behaving like it's supposed to.

    I've read the Unity manual page on Root Motion here:
    https://docs.unity3d.com/Manual/RootMotion.html
    But it didn't help. Either it's something not covered by that or I misunderstood something.

    How should something like this usually work in a 3D game in practice? Is it usually desirable to have the pivot move around and how is that dealt with? I did the animations in Blender with the assumption that the pivot/origin would always be at the model's origin in Blender, but Unity doesn't seem to make it easy to keep it in one place.
     
  2. HeWasAgainstIt

    HeWasAgainstIt

    Joined:
    Jan 20, 2016
    Posts:
    9
    Still haven't figured it out and I'm kind of at a loss. I have experimented a little though and found that leaving the arms static doesn't make any difference to how much the pivot goes upward or anything.

    I wonder is it possible that it's something to do with using IK? The pole targets or some such? Probably not, but I briefly thought about the invisible parts of the .blend file like the IK stuff and lights etc.

    Almost seems like the kind of weird behaviour you'd get from not applying rotation and scale or position after screwing around with things, but IIRC I already applied all of those to everything.

    Any ideas? I might dig deeper into what I can find out about Root Motion in the meantime.
     
  3. TPEUnity

    TPEUnity

    Joined:
    Jan 17, 2018
    Posts:
    12
    Have u set up Bake into pose in your Root Transform Position (Y)? Are you sure the root u set in rootmotion tab is the actual root (that unity thinks is a root?). Not a solution but i can recommend asset called "Umotion" when it come to fixing and tweaking animations (even creating from scratch) in unity, its really a life saver when u get problems like this when something doesnt look like it looks in another program.
     
  4. HeWasAgainstIt

    HeWasAgainstIt

    Joined:
    Jan 20, 2016
    Posts:
    9
    I have experimented with the Root Transform Position (Y) settings, but it hasn't given me anything near the desired effect. IIRC changing the settings around got my model floating at 2 different heights... but not how it looks in Blender, and there's also the strange curving path of the pivot that I can't explain...

    As for Root Motion, I think by the looks of things I probably shouldn't be using Root Motion given I'm just trying to set up a simple animation system and RM appears to be aimed at more complicated animation that demands a greater degree of exact control and fluidity. I thought not using Root Motion was supposed to effectively freeze the model on the spot and eliminate this kind of complication but that hasn't been the case.

    I may indeed have messed up with the root... how exactly is that meant to work? I have it set to <Root Transform>, which seems to work fine for my run/walk animations and does at least give me the correct model orientation whereas all other options apart from <None> cause it to rotate 90 degrees or so.
    Would you generally have to create some form of special bone/object in a 3D program to act as the root node, or should the default be enough? The tutorial above seems to suggest it would usually be fine. I'm starting to suspect there may be some anomaly in my model that is causing the pivot to move around but I have no idea what it might be or why it would move both back and upwards like that when it doesn't seem to correspond to anything...
     
  5. HeWasAgainstIt

    HeWasAgainstIt

    Joined:
    Jan 20, 2016
    Posts:
    9
    Just had another thought: Should it matter how you import the .blend file into Unity? I know you can export as an .fbx from inside Blender and then import that into Unity, but I used the method of just dragging into the Assets. I've heard that works by opening Blender in the background and converting to .fbx so it should be identical I assume, but might there be some export settings that could prevent what's happening here?
     
  6. HeWasAgainstIt

    HeWasAgainstIt

    Joined:
    Jan 20, 2016
    Posts:
    9
    Ok, finally made some progress here.

    My 3D model object has been parented to an empty, with the empty called Player and used for containing everything not directly related to the model like the Character Controller and a movement script. I figured since everything should be relative, and the Idle/Walking/Running animations were looking fine, that the Kneel animation should be correct in relation to those.
    I just tested making a duplicated of my model object and putting it in the scene on its own, then changed my animation controller so it automatically made the Kneel animation play (this is why I didn't try before... thought I'd have to write new versions of some scripts to make it kneel just to try something I didn't think had much chance of making a difference).

    Andddd... it actually no longer floats. The non-parented model appears to stay at the correct elevation, while the parented one continues to float even after I've disabled all scripts in the Player empty (so it's definitely not something with the Character Controller or anything that's doing it). There's still some anomalous behaviour where it sinks into the ground a bit but I think that's just because it's blending between the Kneel and Idle animations, which I need to disable...
    Yep, managed to get that working properly. Now I just have to fix it going out of crouch...

    Is there a simple way to reverse an animation in Unity? i.e. I have an animation of going from standing to crouching, can I set it up to play backwards in order to stand up again, or do I have to create that separately in Blender?

    Christ, turns out that it was happening because I had some really weird scaling values in the Player object and model object... I brought them all back to 1 and fixed the values of the Character Controller so the capsule collider made sense, and now it all seems to work fine with the same setup as before. I must have just been messing around initially and set those values up temporarily for some reason or wasn't paying attention that I was altering one set of values to fit other values that shouldn't have actually been that way and then forgot all about it.
    Ugh, just goes to show that 99% of the time in game development, a problem like this is because of some dumb oversight you didn't even come close to thinking of checking because you assumed the problem was somewhere else.