• 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
0
Question by ivarhill · Aug 18, 2018 at 11:38 PM · transitionmechanimidle

Blend between idle animations using a separate transition animation

I have an enemy object which has two idles - "NormalMode" for when not engaging the player, and "AttackMode" as a battle stance - so the following animations in total:


  • NormalMode (loops)

  • SwitchToAttackMode

  • AttackMode (loops)

  • SwitchToNormalMode

  • Attack (which should blend from any state)


I haven't used mechanim much in the past so I am trying to figure out how to incorporate this flow in a good way, but so far I haven't found any specific documentation on this particular case. Basically, in my script I need to be able to say "Now you should be in attack mode", which blends from NormalMode to the AttackMode using SwitchToAttackMode inbetween - and vice versa.

So far documentation I've seen on animation states only describes how to blend between two states with no specific inbetween animation - but I essentially want the following:


  1. Blend for ~0.2s from "idle" to "SwitchToAttackMode"

  2. Play "SwitchToAttackMode" in its entirety

  3. Blend for ~0.2s at the end of "SwitchToAttackMode" to "AttackMode"


The by far most optimal solution would be to have something like an boolean "isInAttackStance" set up in mechanim that a script can just change, and it seamlessly does the above whenever needed. This is my current mechanim setup:


Mechanim setup


But the above feels a bit wrong, since "SwitchToAttackMode" isn't a goal state in itself, it's just an intermediate step. I suspect I also need a boolean that triggers things properly, but I can't figure out quite how to put it all together.

Could anyone point me in the right direction here? It feels like there should be an easy, obvious way to do this almost entirely within mechanim, but I'm not quite seeing it.

mechanim.jpg (143.1 kB)
Comment
Add comment · Show 4
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 ignacevau · Aug 18, 2018 at 11:54 PM 0
Share

The easiest way to blend between 2 different states, is to have an rigged model, for example made in Blender, and Unity can automatically do the blending for you.

Show more comments
avatar image ignacevau · Aug 19, 2018 at 12:03 AM 0
Share

Try this to use the in-between states such as "SwitchToAttack$$anonymous$$ode": with the arrow between "IdleNormal" and" SwitchToAttack$$anonymous$$ode" selected,

1) Untick the "has exit time" checkbox 2) Check the "fixed duration" checkbox and set the "transition duration" to 0.2 3) Set the "Conditions" to the trigger "SwitchToAttack$$anonymous$$ode"

Then in your script you can simply use

 GetComponent<Animator>().SetTrigger("SwitchToAttack$$anonymous$$ode");

to start the transition.

Then with the arrow selected between "SwitchToAttack$$anonymous$$ode" and "IdleAttack": 1) Check "has exit time" and leave the default values for the exit time (if edited remake the transition) 2) Check the "fixed duration" checkbox and set the "transition duration" to 0.2 3) Leave the "conditions" blank

Show more comments

1 Reply

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

Answer by ivarhill · Aug 19, 2018 at 12:46 AM

Solved with the help of @ignacevau - changed to use bool rather than a trigger, but the basic concept works the same. Seems reliable - thanks for the help!

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

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

Idle and Walk animation don't work at all 1 Answer

Is there a way to turn on a transitions hasExitTime on/off through code? 1 Answer

Copy/Paste Mecanim Transitions 6 Answers

Is it possible to use multiple parameters causing different transitions between two animations? 0 Answers

mecanim move and root 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