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 /
This question was closed Feb 05, 2015 at 02:57 AM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by vnmatt · Feb 01, 2015 at 05:47 PM · animation2dsprite2d-platformer

Animation doesn't play all the way through unless holding the key down

I am new to Unity and I am working on my first 2D platformer.. my player is using the CharacterController2D from here:

https://github.com/prime31/CharacterController2D

I have various animations, like Idle, Walk, Jump, Kick, Punch, etc.. and for the most part they're working just fine. However, the Kick animation consists of 2 sprites (StartKick and EndKick). When I press the key to kick, it only plays the animation half way (to StartKick)... I need to hold the key down to make it play all the way. This is unsatisfactory; I would like to just tap the key and make the kick work all the way without having to hold the key down.

What can I do?

EDIT

By the way, here's my Update method in a script attached to the player (which makes use of the CharacterController2D that I mentioned above:

 public void Update()
 {
     // grab our current velocity to use as a base for all calculations
     velocity = controller.velocity;
 
     if (controller.isGrounded)
     {
         velocity.y = 0;
     }
 
     if (Input.GetKey(KeyCode.D))
     {
         //some logic
     }
     
     // lots of else ifs here... (removed to make it clearer), then for kick:
     
     else if (Input.GetKey(KeyCode.E))
     {
         normalizedHorizontalSpeed = 0;
 
         if (controller.isGrounded)
         {
             animator.Play(Constants.AnimationStateHashes.Rick.Kick);
         }
     }
     else
     {
         normalizedHorizontalSpeed = 0;
 
         if (controller.isGrounded)
         {
             animator.Play(Constants.AnimationStateHashes.Rick.Idle);
         }
     }
 
     // we can only jump whilst grounded
     if (controller.isGrounded && Input.GetKeyDown(KeyCode.W))
     {
         velocity.y = Mathf.Sqrt(2f * jumpHeight * -gravity);
         animator.Play(Constants.AnimationStateHashes.Rick.JumpOrBlock);
     }
 
     // apply horizontal speed smoothing it
     var smoothedMovementFactor = controller.isGrounded ? groundDamping : inAirDamping; // how fast do we change direction?
     velocity.x = Mathf.Lerp(velocity.x, normalizedHorizontalSpeed * runSpeed, Time.deltaTime * smoothedMovementFactor);
 
     // apply gravity before moving
     velocity.y += gravity * Time.deltaTime;
 
     controller.move(velocity * Time.deltaTime);
 }


Comment
Add comment · Show 3
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 meat5000 ♦ · Feb 01, 2015 at 08:36 PM 0
Share

Check your Exit Time parameters in Animator Window

avatar image vnmatt · Feb 02, 2015 at 02:13 PM 0
Share

@meat5000, I don't see anything called Exit Time and after Googling a bit, I think you're referring to something on the animation transitions. I don't have any transitions right now, since I am manually playing the clips myself (You can see this in my code above) and not using the mecanim state machine.

avatar image saschandroid · Feb 02, 2015 at 02:46 PM 0
Share

I guess the 'problem' is the

 else if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.E))
 {
 ...
 }
 else
 {
 ...
 }

logic.

If you stop pressing the 'E'-$$anonymous$$ey, your program enters 'else' and starts playing the 'idle'-animation. You should check if your 'kick'-animation has finished before starting the 'idle'-animation.

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by meat5000 · Feb 02, 2015 at 02:42 PM

It appears that it is becoming interrupted due to the if else logic.

When you release the E key, on the next Update the else is triggered which makes the idle animation kick in. Its really playing less than half but you see half due to the transition to idle, I do believe.

If you don't want to use the State Machine you should implement states in your code instead. You can do this with a switch perhaps. Realistically though, you need to check which animation is currently playing before you call another. This could also be tricky without the state machine as nothing is layered.

Comment
Add comment · Show 1 · 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 vnmatt · Feb 04, 2015 at 02:19 PM 0
Share

Thanks. In the end I actually decided to work with the Unity State $$anonymous$$achine; it's great.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

SpriteManager 2 1 Answer

Sprite animation 2 Answers

How to make not smooth animation? 0 Answers

Animation System in 4.3 1 Answer

How do I stop sprite animation on last frame? 2 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