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 /
  • Help Room /
avatar image
0
Question by tubswitch · Feb 25, 2016 at 02:30 PM · animation2dsprite2d animation

Transitioning between 2D animations by frame

I am having issues with Unity's default 2D animation system, and am curious as to how I can achieve a desired behavior. Within my project, I am attempting to transition between my character's "Run" animation and "Running Attack" animation to allow the character to smoothly attack while moving.

The way I've been looking at handling this is by creating 3 different animations- one normal run cycle, one version of the same cycle with the character drawing their weapon, and a third run cycle with the weapon drawn. This way when the player attacks, the sprite's run cycle would play the next frame of the "Draw Weapon" cycle, then the next frame would be from the "Weapon Drawn" cycle, before returning to the original cycle.

Here is an image from an existing game illustrating what I mean:

alt text

My issue is that I'm not sure exactly how to transition between animations on specific frames. I've considered using a blend tree, but I'm not quite sure it will achieve what I want.

example.jpg (112.3 kB)
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
0

Answer by Zoogyburger · Feb 25, 2016 at 06:08 PM

So you have a run animation and a running attack animation. Create two states in the animation controller with the two animations in them and have them transition to each other. Add a bool perimeter IsAttacking and one transition set the conditions to be IsAttacking to be true and the other to be IsAttacking to be false and add a script like this on to your player:

 Animator anim;

 private bool attacking;

 void Start () {
     anim = GetComponent<Animator>();
 }



     void Update (){

         if (Input.GetKeyDown (KeyCode.Space)) 
         {

             anim.SetBool("IsAttacking", true);
     }
Comment
Add comment · Show 3 · 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 tubswitch · Feb 26, 2016 at 02:47 PM 0
Share

Sorry, I guess I didn't explain the situation clearly.

If you attempt to transition between animations this way (which normally would work fine), it begins the next animation on the first frame of the next animation, rather than the next frame of that animation. Looking at the diagram I posted and using your method, If you were to hit Space on frame 5 of the first row, the animation would switch to the FIRST frame of the second animation, then play the entire second animation clip before playing the third clip.

What I want to do is interrupt on that 5th frame, then play the 6th frame of the second clip, the 7th frame of the third clip, and return to the 8th frame of the first clip.

avatar image Zoogyburger · Feb 26, 2016 at 06:37 PM 0
Share

Oops! I didn't understand what you were trying to do. I guess this sort of thing could be done with blend trees though I'm not exactly sure how. I would use my system above and in script, jump to the certain frame you want:

http://docs.unity3d.com/ScriptReference/AnimationState-time.html http://docs.unity3d.com/ScriptReference/Animator.html

Something like this:

 GetComponent<Animator>()["Attack"].time = 2.45F;
avatar image J0hn4n Zoogyburger · Mar 08, 2017 at 01:31 AM 0
Share

Animator its the interface to control mecanim, not a animation dude.

avatar image
0

Answer by J0hn4n · Mar 08, 2017 at 01:25 AM

weell i had a isuees like that before, i recomend you to use bleend trees only to make things like movement, like if speed its less that 0.5 walk, else run.

its better use "Animation" for attack or things you need to know if has finished, you can set animation.playqued if you want make attack combos ,also you can get the normalized of that animation to do another stuff, like send a damage event when the normalized time reach to 1.

Also you can always make a list of sprites and make your own custom animation.

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

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

Animation events not working for my sprite animation 0 Answers

Adding sprites to same layer as bone in 2D animation rig 1 Answer

How to create a sprite animation template? 0 Answers

2D Animation disables Player Controller Script 1 Answer

Unity2D animation and sprite layout 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