4

I have a marine model used in my start project, which will uncontrollably lift off the ground when running. I import the fbx resources, set the animation type as humanoid and configured the avatar by automatically mapping, set up a animator controller that contains only a running animation. Here is about several seconds after playing:

enter image description here

But when using a generic animation type everything works fine. Any suggestions to fix this while still using the avatar system?

UPDATE:

Configure of my 3D model: enter image description here

Joey.Z
  • 4,492
  • 4
  • 38
  • 63
  • Can you post a picture of your complete 3d model config in the editor? – VicM Mar 07 '14 at 06:32
  • Also does the animation has a translation? Try to freeze or lock (dont recall) the y axis in the 3d model config in the editor – VicM Mar 07 '14 at 06:33
  • @VicM I posted the config. I am a fresher, I don't know if there is a translation in the animation, I copied the models from an older project downloaded in the asset store, which is not using an avatar system or the humanoid animation. And I haven't add a rigidbody to my character, I am gonna try that and freeze the y axis. But rotation exists too. – Joey.Z Mar 07 '14 at 06:54
  • @VicM Yeah, I see there are translations in the animation, and unity prompt a warning saying it is not supported. – Joey.Z Mar 07 '14 at 11:17
  • Well, if you don't need the animation to move up, change that to walk in place or only advance horizontally in maya or so, I also suggest trying another model, and also add a rigidbody. Another thing is that mecanim and normal animation could be clashing a bit, under the animator try unticking appy root motion, also try bake into pose Y. Be sure to try them one by one and read the unity doc to understand what the options do. – VicM Mar 07 '14 at 13:06
  • **NOTE** In most cases, the problem is simple - you have to check BAKE IN TO POSE for "Y". See here: answers.unity.com/answers/1197139/view.html – Fattie Nov 05 '18 at 10:01

5 Answers5

7

This is obviously caused by root motion. What happens is, one loop of your animation takes the character slightly higher. Adding these slight changes up, you get what you're getting. If you don't need root motion (doesn't look like you do), disable it (from the animator component's settings). If you do, either edit the animation to make sure it fits, or disable root motion along the Y-axis (you can do this from the animation's import settings).

In case you don't know what root motion is, it's when the root bone of your model has animations applied. You obviously can't create the entire animation of character running up and down your levels, and until recently (though not MUCH recently) characters where animated in-place, and moved procedurally via code (I know for a fact that Unreal Tournament 3 uses this method, as would any UDK user). Then, people started wondering how they could make their characters move more realistically? I mean, it's not like you walk forward at a constant rate of 4 km/h, you tend to slow down and speed up during different parts of the walk cycle. The same can be applied to video game characters using the technique known as root motion.

With root motion, you actually move the character forward during its animations. This will cause an animation to look really bad in max or maya, since the character will just snap back to its original place after a loop. However, this data is used intelligently in game engines: Rather than use the absolute position the animation yields, you take the velocity out of it between each two frames, and move your character based on that velocity (Unreal engine actually has a really neat acceleration mode for applying root motion, though I'm not really sure how that would be different from velocity mode). This will make your character move forward at the same rate the animation does, and thus you can actually animate the character's movement as well as its limbs and joints. Moreover, since you're using the velocity and not position data from the animation, it will look exactly as you'd expect it to. If you're interested in this technique, take a look at the Mechanim demo pack they have on the asset store. It makes extensive use of root motion to move the character around.

Arshia001
  • 1,854
  • 14
  • 19
  • 1
    For anyone googling here, this is not correct. For the problem posed the solution is simple - you just have to check BAKE IN TO POSE for "Y". See here: http://answers.unity.com/answers/1197139/view.html Naturally root motion is being used to move a character around, but you don't (generally) want the "internal Y jiggle" when eg walking around etc. – Fattie Nov 05 '18 at 10:06
  • It's not "incorrect" either. A high-quality animation clip will only animate the root as necessary with no Y transform. If you have a bad animation clip, baking into pose can be a work-around, but it's ultimately just a work-around. Good luck trying to get root motion working with low-quality animation clips. – Arshia001 Nov 05 '18 at 10:37
  • It's a strange issue in Unity. If you look at a typical (say) walk animation, the Y will of course move up and down with the animation as the animator moves the COM (and of course match at the ends). The fact is in the shambles that is Unity you have to check "Bake in to pose" to make Unity understand it has to match back to that in/out level at *whatever point you exit the loop*. – Fattie Nov 05 '18 at 12:08
  • (When is said "you don't (generally) want the "internal Y jiggle" when walking around etc." of course what I meant was you don't want it to additively build over each loop :) ) – Fattie Nov 05 '18 at 12:09
  • 1
    That small amount of movement can be caused by floating point errors and not just in Unity (try javascript!). The fact is, you don't want Y movement on your walk animations at all. End of story. If you want to animate the center of mass, give it a ***separate*** bone. – Arshia001 Nov 06 '18 at 13:17
  • ? as humans walk your head moves up and down (something of a sine curve), as does your hip point etc. (Also you're at a slightly lower average height than standing still (idle), since your knees are bent, lower still when running of course.) Look inside any animation, whatsoever, at the root pos. curves. Anyway no need to go back and fore since we may just be mis-communicating. In Unity you have to click Bake-Y for walking-type (XZ) root motion animes. Cheers, out! – Fattie Nov 06 '18 at 16:43
  • Yes, I know how human walking works (I'm a human and I walk). When you make *computer animations* for *computer models* of humans (not real humans!), you generally make a root bone and give it root motion, while also making a hip bone that's a *child* of the root bone, and putting any other animation there. – Arshia001 Nov 06 '18 at 20:49
2

My company was having a similar issue but we still wanted to keep the "Apply Root Motion" toggle checked. When the same animation played on loop, the model stayed in place but if several different animations were played one after another, this caused the model to rotate / shift in position. The solution for us was ticking these check boxes in the animation settings for each animation. Root Transform Rotation, Root Transform Position (Y), Root Transform Position (XZ).

Dr Nick
  • 21
  • 1
  • 1
    This is correct - the answerer here is describing the "Bake in to pose" buttons in animation import. Note that, almost always, you simply turn on bake, and that is ONLY for "Y". (Of course .. the character is actually walking/etc on X and Z !) answers.unity.com/answers/1197139/view.html – Fattie Nov 05 '18 at 10:04
1

I had the same issue a few days ago. I found out that the problem was the Apply Root Motion in the Animator script. Make sure it's unchecked.

pek
  • 17,847
  • 28
  • 86
  • 99
0

Tag your player with "Player" in scene and use this script

float y;
GameObject player;

void Start ()
{       
 player =  GameObject.FindGameObjectWithTag("Player");
 y = player.transform.position.y;
}

// Update is called once per frame
void Update ()
{
 float diff = player.transform.position.y;
 player.transform.Translate ( 0, 0,z - diff);
 y = player.transform.position.y;
}

it is little hacky soultion but works!! note: if you want to use y movement at some point just calculate and add it to diff variable.

Jitendra
  • 1,107
  • 2
  • 12
  • 22
  • This doesn't work in modern Unity or generally when animating a character. The solution is simple, you just need top "Bake" on Y. – Fattie Nov 05 '18 at 10:03
0

For those who couldn't solve this issue with 'bake into pose'. I tried 'Bake into Pose-Y', but it didn't work. Meanwhile, in FBX > Animation > Motion, I set 'Root Motion Node' as 'Root Transform'(It was 'None' before), it solved my problem. Unity version is 2020.3.34f1.