• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by vexe · Aug 06, 2014 at 03:59 PM · animationmecanimroot motion

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:

alt text

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!

states.png (25.3 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vexe · Aug 06, 2014 at 04:22 PM 0
Share

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...

avatar image
1

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

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image vexe · Aug 06, 2014 at 04:29 PM 0
Share

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...?

avatar image meat5000 ♦ · Aug 06, 2014 at 04:47 PM 0
Share

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 :)

avatar image meat5000 ♦ · Aug 06, 2014 at 04:59 PM 1
Share

Root $$anonymous$$otion Animation

alt text

rootmotion.jpg (159.7 kB)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mecanim: 2D Blend Trees, Unable to Compute Positions. 0 Answers

Mecanim curve for move speed 0 Answers

Does anybody have best practices on creating an action-adventurer character (Mecanim)? 0 Answers

Mecanim - how can I use traslation and rotation of Root from separate animation clips? 0 Answers

position change due to animation 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges