Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 WujekEvil · Aug 13, 2015 at 04:10 AM · animationmecanimtransition

Interrupting animations

I am making 2D top-down view game and I would like the player to be able to cancel certain animations while they are playing.

Let's assume I have an idle animation and a simple animation of swinging a sword. Idle animation does nothing but sets the sword rotation to 0 degrees. Swinging animation rotates the sword from 0 to 90 degrees.

I would like to be able to cancel the sword swing animation at any time. The problem is for smooth transition between animations I would need to start the backswing animation with the same rotation of sword as in the swing animation at the moment when it was interrupted.

So I've prepared backswing animation which was mirrored swing animation: it rotates sword from 90 to 0 degrees.

I've tried using blending tree to blend between those two animations and it worked well unless the input which cancelled animation occured after half of swing animation time: the backswing animation only played for the remaining half of animation time and it ended before reaching the 0 degree rotation, which caused sword to jump.

I thought of starting the backswing animation at frame in which sword rotation is the same as it was when the swing animation was interrupted, but for this I would need to be able to set transition offset of backswing animation dynamically, depending on the moment of interrupting swing animation.

So my question is: Is there any way to set the offset of transition dynamically by script? Or is there any other way to achieve smooth transition if the starting position of next animation needs to be based on interrupted frame of current animation?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by WujekEvil · Aug 16, 2015 at 06:43 PM

Seems like I found out a solution I needed. Attaching following behaviour script to swing animation makes the animation transition smooth and starting from desired rotation:

 // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
     override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) 
     {
         //"Block" is my trigger for interrupting weapon swing animation
         if(animator.GetBool("Block")==true)
         {
             //the 4th parameter is the offset of transition
             animator.CrossFade("Cancel", 0f, layerIndex, 1f-stateInfo.normalizedTime);
             animator.SetBool("Block", false);
         }
     }
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

2 People are following this question.

avatar image avatar image

Related Questions

One animation breaks playing another 1 Answer

Mecanim Root Motion Rotation - 180 degree turn. 2 Answers

Mecanim transition between animation help 0 Answers

Combining two animations to be one 0 Answers

How can i jump my character immediately With Mecanim 3 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