Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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.

avatar image ivarhill ignacevau · Aug 18, 2018 at 11:58 PM 0
Share

Well, the core of the issue is that it isn't simply a blend between two different states. This model in particular is a hovering droid, and it has multiple parts that move around as it changes from the idle to the attack stance - so the transition in itself has to be a separate animation (which it currently is - all the above animations are done in $$anonymous$$aya and exported to Unity).

So I need a way to essentially blend to a second state with a third state playing its full length inbetween: IdleNormal -> SwitchToAttack$$anonymous$$ode -> IdleAttack.

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

avatar image ivarhill ignacevau · Aug 19, 2018 at 12:30 AM 0
Share

Thanks, this clears things up a bit - it does seem to work fairly well to simply use a trigger as a condition, and I think I didn't understand clearly enough that states always transition to connected states unless there's a condition controlling it.

I'm still having some issues making all states flow between each other - currently it sometimes jumps to unexpected states - but I'm suspecting that's just a matter of double-checking the conditions and calls in the script. Will keep trying a bit, thanks for the assistance!

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.

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