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 Jazzds · May 06, 2015 at 12:44 PM · animationtransitiondefault

Transitions being ignored in Animator Tree

So like I been having this problem for awhile and I'm honestly not sure if it's the code or the Animator that I have set up wrong. So my problem is that I have sort of two idle animations. One is the main default animation that it starts with and then I wanted to have when you target an enemy, it switches to an attack mode idle mode. Probably is that even with or without an exit time, the animations overlap each other and it still tries and goes back to the main idle even though the transition set up shouldn't allow it.

I'm really scratching my head cause if I can't get this to work, I won't be able to set up other animations correctly either.

Code is Below (please ignore the fragments of legacy code, it is a WIP upgrading code lol):

 #pragma strict    
     var speed : float = 6.0;
     var jumpSpeed : float = 8.0;
     var gravity : float = 20.0;
     private var moveDirection : Vector3 = Vector3.zero;
     var animator : Animator;
     var target: Transform;
     
     
     
     function Update() {
         var controller : CharacterController = GetComponent(CharacterController);
 
           animator = GetComponent(Animator);
 
         if (controller.isGrounded) {
             // We are grounded, so recalculate
             // move direction directly from axes
             moveDirection = Vector3(Input.GetAxis("Horizontal"), 0,
                                     Input.GetAxis("Vertical"));
             moveDirection = transform.TransformDirection(moveDirection);
             moveDirection *= speed;
             
             if (Input.GetButton ("Jump")) {
                 moveDirection.y = jumpSpeed;
             }    
         }
         
         // Directional Movement with Arrow Keys and WASD
         
         if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.W) || 
             Input.GetKey(KeyCode.S)) {
             animator.SetFloat("arrowKey", 1.0);
             animator.Play("note_walk01");
             }
         else {
             animator.SetFloat("arrowKey", 0.0);
             animator.Play("note_idel01");
             }
             
         if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) {
             //animator.Play("note_idel01"); 
             transform.Rotate(0, -1, 0);}
         if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)){
             //animator.Play("note_idel01"); 
             transform.Rotate(0, 1, 0);}
 
         // Attack animations to be triggered when attacking
         
         if (Input.GetKeyDown(KeyCode.Tab)){
             target = GameObject.FindWithTag("Enemy").transform;
               animator.SetBool("foundEnemy", true);
           }
             
         if (Input.GetKey(KeyCode.F)) { 
             animator.SetFloat("attackButton", 1.0); 
             }
         else { 
             animator.SetFloat("attackButton", 0.0); 
         }
         
         
         
         
         // Apply gravity
         moveDirection.y -= gravity * Time.deltaTime;
         
         // Move the controller
         controller.Move(moveDirection * Time.deltaTime);
     }


And my animation tree that I have currrently up and running.... kinda

alt text

screenshot-20150508135533.png (84.9 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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by DiegoSLTS · May 08, 2015 at 07:04 PM

It's hard to know where's the problem without the animator and the transitions, but I see odd things in your code.

  • You're using float parameters for things that look like booleans. It's not a big deal, but it can be confusing.

  • You set those float values to 1 or 0 on every frame instead of using only the frames when the keys are pressed or released. Again, is not a big deal, but it might confuse you later.

About those 2, I'd use bool parameters instead of floats, and write things this way (just an example):

 if (Input.GetKeyDown(KeyCode.F)) {
     animator.SetBool("attackButton", true); 
 }
 else if (Input.GetKeyUp(KeyCode.F)){ 
     animator.SetBool("attackButton", false); 
 }

What looks more important is that in some places you're setting parameters (which might trigger some transition to a new animation clip) and immediatelly use the "Play" method. It's like you're mixing stuff, you're moving between states using an indirect approach (setting values and letting the states change if needed) and manually. I don't know how to fix that, you should properly set your transitions to work with only one scheme, if pressing "Up" is supposed to trigger some animation, then "SetFloat("arrowKey",1)" should be enough to trigger it, without the Play line.

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 Jazzds · May 08, 2015 at 07:41 PM 0
Share

:D so I got the idle issue fixed! There is just a problem now with the animations not looping but I figure that the animation itself that is the issue right?

EDIT: Yes it was the animation and thank you so much for helping me find the issue!!!

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

Animation will not Return to Proper State 2 Answers

Mecanim transitions sometimes don't work 4 Answers

2D Animation Instant Transition 2 Answers

Animating Transitions for GUI Results 0 Answers

Have one animation segue into another 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