Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 RealNiv · Oct 30, 2020 at 09:47 PM · animationsanimation controller

Animation triggers doesn't work as expected

Hello, my team and I are using animations triggers to handle the animation transition in a top-down 2d game. We have a problem with the animation transitions, sometimes the tranitions between directions work fine but sometimes the wrong animations are triggered, even though when we have debugged the code, (for example Debug.Log("WalkRight") where it should be triggering this particular animation), the code seem to work as it should be. So I'm pretty sure the bug is in the transitions but we couldn't find it. This is the animation controller we made for the enemy:

alt text

This is an example of a transition: alt text

And this is the code we use to decide which animation to trigger:

 void ManageAnimation()
     {
         int Q = FindQuarter(moveDirection);
         if (Q == 1)
         {
             if (moveDirection.x > (moveDirection.y + 0.5f))
             {
                 anim.SetTrigger("EnemyWalkRight");
             }
             else
             {
                 anim.SetTrigger("EnemyWalkUp");
 
             }
             
         }
         else if (Q == 2)
         {
             if (Mathf.Abs(moveDirection.x) > moveDirection.y + 0.5f)
             {
                 anim.SetTrigger("EnemyWalkLeft");
             }
             else
             {
                 anim.SetTrigger("EnemyWalkUp");
             }
                 
         }
         else if (Q == 3)
         {
             if (Mathf.Abs(moveDirection.x) > Mathf.Abs(moveDirection.y) + 0.5f)
             {
                 anim.SetTrigger("EnemyWalkLeft");
             }
             else
                 anim.SetTrigger("EnemyWalkFront");
         }
         else if (Q == 4)
         {
             if (moveDirection.x > Mathf.Abs(moveDirection.y) + 0.5f)
             {
                 anim.SetTrigger("EnemyWalkRight");
                 
             }
             else
                 anim.SetTrigger("EnemyWalkFront");
         }
     }
     int FindQuarter(Vector2 direction)
     {   // Finds the quarter that the end of the direction is in.
         if (direction.x > 0 && direction.y > 0)
             return 1;
         else if (direction.x < 0 && direction.y > 0)
             return 2;
         else if (direction.x < 0 && direction.y < 0)
             return 3;
         else if (direction.x > 0 && direction.y < 0)
             return 4;
         return 0; // it is on one of the axis.
     }

Can anyone tell what can be the problem?

animations1.png (43.7 kB)
animations2.png (18.8 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
1

Answer by digitj · Apr 21 at 09:39 AM

Just use blend trees

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 Avexpert · Apr 21 at 09:46 AM

Try not to use SetTrigger. Instead, use SetBool for the bool parameters that you set in your animator. Don't forget to assign these bools into your transition lines. Like ;

anim.SetBool("isWalking",true);

I also suggest you to watch some tutorials about State Pattern. By that way the process will be more accurate and less painfull.

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

147 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 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 Rig Import Problem 1 Answer

Character's animation distorts 0 Answers

Mirroring animation clip without mirroring root motion node? 0 Answers

Character animation position 1 Answer

how to use parameters with blend tree? 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