• 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 CandlewaxJames · Dec 01, 2012 at 06:29 AM · animationmecanim

Mecanim MatchTarget Varied Results

As a test I created a script to detect when a character runs into a wall and move them to Vector3(0,0,0) when they do using Animator.MatchTarget.

However the character doesn't always move to the same position. Sometimes they will stop halfway and sometimes they will not move at all. The animation plays every time so I know that MatchTarget is being called (it's in the same if statement as the code to play the animation). It seems to work the first couple of times then just stop completely. The relevant code is below:

 // The wall collision
     var hit : RaycastHit;
     if (Physics.Raycast (this.transform.position, this.transform.forward, hit, 1.0) && (targetSpeed * this.maxSpeed) > 4) 
     {
         this.anim.SetBool('WallPush', true);
         this.targetSpeed = 0;
         InputManager.Instance().disableInput = true;
         this.anim.applyRootMotion = true;
         anim.MatchTarget(Vector3(0,0,0),Quaternion.identity, AvatarTarget.RightFoot, MatchTargetWeightMask(new Vector3(0, 0, 1), 0), 0.0, 1);
     }

Does anyone know why MatchTarget would behave this way?

Comment
Add comment · Show 1
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 wangzy_88 · Apr 12, 2014 at 06:04 PM 0
Share

At first,the first time correct and latter times error.After I disable controller when use $$anonymous$$atchTarget,always error... Could you share some ideas?

2 Replies

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

Answer by Joachim_Ante · Dec 02, 2012 at 10:26 PM

Is the root motion being applied 100%. Is it possible that a character controller or rigidibody collision is preventing it from reaching the target. MatchTarget assumes that the rootmotion is applied completely.

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 CandlewaxJames · Dec 02, 2012 at 10:43 PM 0
Share

Thanks for responding. I think it is, is their a way to check? On a side note, does this method need to be called repeatedly whilst the animation is being played? EDIT: After disabling the character controller and testing it again, it started working correctly. Thank you for pointing that out! I'm so stupid for not thinking of that.

avatar image
0

Answer by Joachim_Ante · Dec 03, 2012 at 12:17 PM

I'd suggest taking control of root motion yourself. Implement OnAnimatorMove yourself.

When you create more complex character controllers that is usually necessary. Eg. during MatchTarget you might want to disable collisions. But really this is highly game specific, depending on exactly the situation you are doing a MatchTarget in and what you want to achieve.

Comment
Add comment · 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

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

13 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

Related Questions

Add more bones to skeleton - vertebraes definition...? 0 Answers

How to create a 2D rig? 1 Answer

Multiple Animation Events not firing 1 Answer

Tweaking a Walk Cycle 0 Answers

With animator, ow to transit quickly from an animation, and transit back without replaying the complete animation 0 Answers


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