Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by Clopay · Jan 20, 2014 at 05:35 AM · animation2d animationtransition

2D Animation Instant Transition

Hey guys,

I'm having issues with Unity transitioning my 2D sprite animations instantly. This question was already asked here but doesn't look like it's getting enough attention.

Goal I've got a 2D sprite animation for a few different states of my character that I'd like to transition between instantly.

Problem my character's default state is idle. This entire animation is 2 seconds long (2 frames, each playing for 1 second). The walk animation lasts for 2/3 of a second (2 frames, each lasting 1/3 of a second). Once my speed is greater than 0.01, I transition to my walk animation. That happens instantly. Once the speed is below 0.01, it is SUPPOSED to transition back to idling, but it often waits an entire second until the idle animation starts playing (even though the velocity is 0 at this point, so my character is walking in place).

I've tried everything I can think of - checking/unchecking the "atomic" option, adjusting the sliders on the transition bar, adding/adjusting an exit time condition, and even scripting the animation completely. I just cannot seem to get this simple thing right. It gets worse when I add in additional states, but I'm just trying to know out the idling - walking - back to idling for now.

Anyone know what's up? Any input is greatly appreciated :)

-Clopay

Comment
Add comment · Show 2
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 Clopay · Jan 20, 2014 at 05:16 AM 0
Share

Update - editing the input axes for 2D has no effect - neither for key/mouse OR joystick input.

avatar image Clopay · Jan 20, 2014 at 03:26 PM 0
Share

Thank you, Santosh!

The suggestion you've got is what I'm currently running with, so I know we're on the right track.

I have narrowed it down to the input axis gravity.

Basically I am using Input.GetAxis("Horizontal") for my left/right movement ins$$anonymous$$d of Input.GetButton("Button"). I'm doing this so that the player is not only movable by left/right, and AWSD keys, but also joystick input if they are using a game controller.

The input gravity I mentioned is a setting found in Edit > Project settings > Input. The input gravity defines how quickly the horizontal value (or any other defined value) resets to zero after pushed. This parameter only takes effect if the input type is a button or a key; however, since $$anonymous$$e is an axis, it has no effect. This is a smart thing to do for Unity, but I am at a loss as I don't know how to overcome this without sacrificing the ability to control my plater with a game controller!

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Santosh Patil · Jan 20, 2014 at 11:08 AM

You can use following code to make instant transition between animation state.

 Animator anim;
 float runSpeed;//change run speed with your input control
 void Start()
 {
     anim = GetComponent<Animator>();
 }
 void Update()
 {
    anim.SetFloat("Speed", Mathf.Abs(runSpeed));
 }

//-------------------animator settings------------------

make two state as 1> Idle

               2> Walk 


make transition from Idle state to Walk click on transition, see Inspector below conditions select "Speed" tag and set "Greater" and speed value to 0.01. make transition from Walk to Idle Speed->less->0.01

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
avatar image
0

Answer by Mijdax · Mar 12, 2016 at 08:15 PM

You Probably had the Same Problem as I had. The float which you set (velocity in my case) will slowly decay until its 0 again and while it is not 0 it will keep animating the running state.

What I did: I added variables for MoveDown,Up,Left and Right (Bools) in the animator and in code I checked

IF velocity.x < -0.05f DO MoveLeftInAnimation == true ELSE MoveLeftInAnimation == false

So as soon as velocity.x drops higher than -0.05 (and lower than 0 of course) it will tell the animator the the character stops walking left

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

19 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

Related Questions

Animation dont change when it should change 1 Answer

Create animation transitions via script. 0 Answers

Animation with bones, Limb Solver knee is bending in wrong way 1 Answer

Talking animation with phonemes smooth transition 0 Answers

How to make a transition animation, intermediate animation between two main states 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