- Home /
Mecanim Issues: Root motion not being applied, and weapon is out of place
So I never got to really mess with animations till now (My first time doing this stuff)
I wanted some basic stuff like idle, running, walking and aiming. I couldn't really find a good aim animation anywhere (I'm no animator) - The only thing I liked was the character from the Locomotion system.
From there, the animations were all imported as separate .fbx files - they were all Legacy so I turned them into Humanoid. I dragged the animations I wanted and so here is my state machine:
The animations are transitioning correctly, here's what's controlling them:
using UnityEngine;
public class MecanimTestController : MonoBehaviour
{
public float rotationSpeed = 1f;
void Update()
{
var animator = GetComponent<Animator>();
if (animator)
{
animator.SetFloat("Speed", Input.GetAxis("Vertical"));
animator.SetBool("IsAiming", Input.GetMouseButton(1));
animator.SetBool("IsRunning", Input.GetKey(KeyCode.LeftShift));
}
transform.Rotate(0, Input.GetAxis("Horizontal") * Time.deltaTime * rotationSpeed * 100f, 0);
}
}
The problem I'm having though is that the character doesn't move even though "Apply root motion" is ticked. He doesn't even more when I preview the animation! (at the bottom right corner of the animation) - Also, the guns are always out of place. Here's a small video highlighting the problems, showing my avatar settings, import settings, etc. - Please give it a view.
Question is: Why isn't root motion being applied? (why isn't the character moving) and why is the gun being offset-ted?
Thanks for any help!
Answer by Josh1231 · Aug 06, 2014 at 04:12 PM
The guns can be kept in place by making it the child of the hand and ammo quaver, and the character can be moved with script by doing
if (animator.GetCurrentAnimatorStateInfo(0).IsName("Base.RunForward"))
Base. being the first layer, and RunForward being the state name, and if it's true you can do what the root motion was supposed to do.
Thanks that's actually correct! - I thought it was parented because it worked when it was a legacy anim. But it wasn't, the guns were children of the "Reference" gameObject.
So that's the second part of the problem solved, still the root motion...
Answer by meat5000 · Aug 06, 2014 at 04:15 PM
http://docs.unity3d.com/Manual/ScriptingRootMotion.html
Root Motion only works 'as-is' when the Animation moves from the spot in the Animation tool/ Modeller.
Otherwise, you may very well need this function
Hi meat thanks for the answer. I understand that if I don't want root motion I should script the movement. But what I don't get is why isn't root motion working. "Root $$anonymous$$otion only works 'as-is'" - does that mean that if animation is exported without root motion, there's no root motion...?
An In-Place animation contains no Root $$anonymous$$otion as the 'Root' doesn't actually move from the spot in the animation itself. These are usually marked as Legacy.
To make this Root $$anonymous$$otion you can either use curves to provide the velocity or script it in to the OnAnimator$$anonymous$$ove() function.
If the animation actually IS supposed to be Root $$anonymous$$otion, it could be that X/Z is baked in the Animation Import.
$$anonymous$$y first link is a page on Adding Root $$anonymous$$otion to In-Place animation. It's all in there :)
Your answer
Follow this Question
Related Questions
Mecan and root rotation in X, Z axis (pitch and roll) 2 Answers
Root Motion issue 1 Answer
How to fix this Mechanim root motion problem? 0 Answers
Root motion with attack animation 0 Answers
MecAnim Root Motion - How To Prevent It 2 Answers