• 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 spk · Mar 28, 2013 at 04:49 PM · mecanim

How to implement weapon-dependent character stances using Mecanim?

My player character uses different weapons, ranging from pistol to heavy machinegun weapon types. I would like the player character overall animation stance to be based on the type of weapon currently equipped. For instance, he will carry and fire the machinegun from the hip and have a rather heavy walk/run animation, while the pistol will use a different fire/reload/run animation set.

What is the best strategy to implement this system using a generic mecanim rig? Shall I setup one animation controller per weapon type, or a single one with specific branches for each type of weapon?

Using the legacy animation system, I would simply replace the run/fire/reload animation at run-time with the weapon-specific run/fire/reload one based on currently equipped weapon. I'm not sure how to translate that to mecanim though.

Any pointers on the topic are much appreciated!

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
4
Best Answer

Answer by TonyLi · Mar 28, 2013 at 07:00 PM

In Unity 4.1, you can change animation controllers at runtime, so multiple animation controllers might be a good option if you synchronize them so there isn't a stutter in the animation when you change.

If you're using Unity Pro, consider using Sync Layers. Your Base Layer can define typical run/fire/reload/etc. states. Additional layers sync'ed to Base Layer will fill in the states using weapon-specific animations. When you change weapons, you simply smooth out the old weapon layer's weight to 0 and smooth in the new weapon layer's weight to 1.

On my current project, I took a different route and built one animation controller with sub-state machines for different weapons on the same Base Layer. Changing weapons means transitioning from one sub-state machine to another. I chose this approach for two reasons:

  1. There was a beta bug (since fixed) with sync layers, and

  2. I'm using G1NurX's Event System for Mecanim (http://u3d.as/content/g1nur-x/event-system-for-mecanim/3QP) to trigger Fire() messages. Each weapon's fire animation needs to trigger Fire() at a different time. It was easiest to separate them out into separate state machines to prevent multiple Fire() messages (only one of which would be valid for the active weapon).

This approach has worked really well for me. Hope these ideas help!

Comment
Add comment · Show 2 · 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 scifresh · Feb 08, 2016 at 01:36 PM 0
Share

hi @tonyli, the answer is really good and what i was looking for. can you show an implementation of a sub state machine ?

avatar image TonyLi scifresh · Feb 08, 2016 at 02:54 PM 0
Share

Hi - This answer is really old, and things change quickly in this industry. But sub-state machines remain the best way to organize different stances. Here's a great example from Opsive's excellent Third Person Controller product: http://www.opsive.com/assets/ThirdPersonController/images/ScreenshotG.png

There are sub-sub-state machines within each sub-state machine, btw.

Transitions within a stance-based sub-state machine are handled by regular transition arrows.

Transitions that switch stances use Animator.CrossFade() to avoid the ridiculous number of transitions that would be needed between all of the sub-state machines.

avatar image
1

Answer by scifresh · Feb 07, 2016 at 12:41 AM

there is a great article about it.

http://www.faq.rpg-kit.com/discussion/2901/tutorial-weapon-specific-animations-using-mecanim

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

12 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

Related Questions

mecanim, adjusting character stance with mouse input using c# script 0 Answers

animation problem in mecanim 1 Answer

Use mecanim for FPS animations? 1 Answer

Mecanim problem with setting speed 0 Answers

Mecanim control animation frames via script? 2 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