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 Apr 06, 2013 at 12:21 AM by Chronos-L for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Chronos-L · Apr 05, 2013 at 08:34 AM · animationanimatormecanimanimator controller

Mecanim Transition-Arrow Pulsing

I just start learning how to work with Mecanim, I have figured out how to setup a generic characters, now I am trying to figure out the Animator.

A very basic state machine

alt text

I set the transition condition from Idle->Move to be [ speed > 0.1 ] and Move->Idle [ speed < 0.1 ].

In my test script:

 using UnityEngine;
 using System.Collections;
 
 public class MecanimControl : MonoBehaviour {
     
     private Animator animator;
     
     void Start () {
         animator = GetComponent<Animator>();
     }
     
     void Update () {
         if( Input.GetKeyDown(KeyCode.A) ) {
             animator.SetFloat("speed", 0.5f);
         }
         else if( Input.GetKeyUp( KeyCode.A ) ) {
             animator.SetFloat("speed", 0f);    
         }
     }
 }

What happen now is: when I pressed A, the transition happens more than once. My character blend to Move, then snap back to Idle and blend back to Move again. I noticed that the transition arrow (the selected one, in blue) is showing a progress line, which means it is re-transit from Idle to Move again.

From my understanding in state machine, once I transit to the Move, my current state would be Move, therefore the transition condition [ speed > 0.1 ] for Idle To Move should not work. The only condition I will be abiding to when I am in the Move-state should be [ speed < 0.1 ].

Am I missing any settings or fundamental ideas on Mecanim? Please enlighten me in this issue.


[Edit #2] Blend Tree

sort of fix the moving problem by using a blend tree. alt text

However, the transition problem still persist.

 void Update () {
         if( Input.GetKey(KeyCode.A) ) {
             animator.SetFloat("speed", 1f, 1.5f, Time.deltaTime);
         }
         else {
             animator.SetFloat("speed", 0f, 0.2f, Time.deltaTime);    
         }
         
         if( Input.GetKeyDown(KeyCode.S) ) {
             Attack();
         }
     }

When I pressed S, I set a bool to play an attack animation. However, since the bool stays true, it will keep on transit from idle -> attack over and over again.


Solution

by EliteMossy*

Do not connect AnyState to Idle (Period)

It solves my first problem with speed.

For my attack-bool in the second part of my question, It will stay true and stuck at the attack-state. To fix that, I used the exit-time to transit back to idle, I also make sure that the attack-bool is set false a short while after it is set true, so that I will transit to attack-state whenever I want to.


screenshot.32.png (7.8 kB)
screenshot.33.png (14.4 kB)
Comment
Add comment · Show 12
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 Chronos-L · Apr 05, 2013 at 08:35 AM 0
Share

I have Googled "mecanim transition once", "mecanim stay at state" without much result.

avatar image Chronos-L · Apr 05, 2013 at 12:12 PM 0
Share

For my idle and walk, my setup is:

alt text

alt text

Transition Requirement:

Idle -> $$anonymous$$oving : [speed > 0.1]

$$anonymous$$oving -> Idle : [speed < 0.1]

screenshot.35.png (16.7 kB)
screenshot.34.png (18.2 kB)
avatar image EliteMossy · Apr 05, 2013 at 12:16 PM 0
Share

Screenshot's not showing, what is the speed float (in the bottom left corner of animator) showing when it is transition from move > idle ? Because it seems weird.

avatar image Chronos-L · Apr 05, 2013 at 12:21 PM 0
Share

I can see the screenshot just fine.

alt text

alt text

screenshot.36.png (23.1 kB)
screenshot.37.png (21.7 kB)
avatar image EliteMossy · Apr 05, 2013 at 12:35 PM 0
Share

Only thing i can think of is you have not set Loop Pose on the animation clip.

Show more comments

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by EliteMossy · Apr 05, 2013 at 01:00 PM

I fixed your issue, you had a transition between Any State and Idle state :D

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 Gurc · Apr 05, 2013 at 05:00 PM

I must say you use wrong function call. Input.GetKeyDown() is triggered once when you press button. Next frame bool is set to false, so does you speed. Use Input.GetKey(); I suppose the rest was right from the beginning.

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 Chronos-L · Apr 06, 2013 at 12:06 AM 0
Share

I must say you use wrong function call. Input.Get$$anonymous$$eyDown() is triggered once when you press button. Next frame bool is set to false, so does you speed. Use Input.Get$$anonymous$$ey();

I neither agree nor disagree.

 if( Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.A) ) {
     animator.SetFloat("speed", 0.5f);
 }
 else if( Input.Get$$anonymous$$eyUp( $$anonymous$$eyCode.A ) ) {
     animator.SetFloat("speed", 0f);  
 }

When I press A, speed will set to 0.5; even thought Input.Get$$anonymous$$eyDown() will not return true in the next frame, speed will stay at 0.5 and will not change to 0 until I release A in Input.Get$$anonymous$$eyUp().

This will not create any re-transition from idle-state -> move-state, this code is not okay because it will produce jagged transition between animations because the speed are set abruptly, not in a smooth lerp .

I suppose the rest was right from the beginning.

The only thing that is causing my problem is my setting/configuration mistake on the controller in the beginning. I should not connect AnyState to my Idle-state.

Follow this Question

Answers Answers and Comments

12 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

Related Questions

Animation Mecanim - Parts of model displaces after animating 0 Answers

unity freezes when running sprinting animation 0 Answers

How to get length of animation in Mecanim? 1 Answer

What is the proper way to wait for an Animator Controller to update? 1 Answer

Can't set animator bool to True 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