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
0
Question by diamondpick · Dec 30, 2014 at 03:59 AM · c#2d

Troubles with 2D character anims with multiple states

Hello, very new to Unity: 2nd day in. As practise I am trying to recreate Samus (Metroid) movements from the SNES sprite-sheets within Unity.

My problem currently lies with falling and jumping. It's difficult to explain everything without posting a screenshot of my Animator state machine as there are lots of animations depending on where the player is facing.

My questions are

1) How do you determine when a 2D character "jump" animation should stop, before a "fall" animation begins? Currently I am measuring rigidbody2D.velocity.y; with some bools on the animator to differentiate the direction of the player:

     float vSpeed = rigidbody2D.velocity.y;

     if (!falling) {
         // Check if we're in the air.
         if (!grounded && vSpeed > 0.2) {
             // Set the jump animation.
             if(facingRight) {
                 animator.SetBool("JumpLeft", false);
                 animator.SetBool("JumpRight", true);
             }
             else {
                 animator.SetBool("JumpLeft", true);
                 animator.SetBool("JumpRight", false);
             }
         }
     }

     // Check if we're falling.
     if (!grounded && vSpeed < 0) {
         // Set the fall animation.
         if(facingRight) {
             animator.SetBool("FallLeft", false);
             animator.SetBool("FallRight", true);
         }
         else {
             animator.SetBool("FallLeft", true);
             animator.SetBool("FallRight", false);
         }
     }

This may be a schoolboy error but my "fall" code doesn't seem to run when a jump animation has finished.

2) My code is already becoming cluttered with "SetBool" calls to the Animator to trigger the various states. Is this normal for complex 2D character animations? I would like to tidy things up a bit.

3) Is there a better way of handling multiple states for 2D characters? Think: look left, gun triggered left, gun triggered up, gun triggered diagonally down, gun triggered down, falling gun triggered down, etc. etc. I would potentially have to handle quite a few states; is there a way to compartmentalise those, yet have them remain in the same... thing? :)

Thank you!

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

0 Replies

· Add your reply
  • Sort: 

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

What is wrong with my Counter Script? (C#) 1 Answer

Distribute terrain in zones 3 Answers

Using Texture Assets in Code 1 Answer

Multiple Cars not working 1 Answer

How to update assigned vector variable in unity C# 1 Answer


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