• 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 /
  • Help Room /
avatar image
0
Question by ahmidou · Feb 03, 2016 at 01:32 AM · state machine

Need advices on stateMachines and transitions setup.

Hi everyone, I'm a unity beginner and this is my first post here.

I'm working on a character that needs to driven by a person in a live presentation with a basic realtime microphone talk (I'm using Salsa).

The character have some idle states that are played in a random order and for a random amount of time, and at any time the "player" can take over and run states related to his mood, or what he's talking bout. Those activated states can be facial expressions or a full body animation.

So I started to mock up that state machine, here "left" and "right" are still idle poses, it's just some slow bending so the character is not too static:

alt text

Each transition have an integer id and in the state machine behavior a timer is ran and switch to a new state id when the duration is over.

 public class idle_blending : StateMachineBehaviour {
 
     private float timer = 0;
     private float rnd = Random.Range(5f, 10f);
 
     // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
     override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
         if (timer < rnd) {
             timer += Time.deltaTime;
         } else {
             animator.SetInteger("idleIndex", Random.Range(0, 3));
             rnd = Random.Range(5f, 10f);
             timer = 0;
             return;
         }
     }


It's kind of working, but the problem is I don't know how many out transitions each state is connected to and I'm currently setting an arbitrary maximum, which means I can have a miss when the random number is higher that the transitions count. Now my questions are:

-Am I doing it the right way?

-I'm not sure if I need to do that in a MonoBehavior or a stateMachineBehavior? It seems it can be done in both.

-How do I access the number of output transitions of the current playing state so I can get a random integer between 0 and the state transitions count -1 ?

And I need to do this at runtime of course.

Any help will be much appreciated! Thanks.

statemacine.png (41.1 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
0

Answer by ahmidou · Feb 03, 2016 at 07:16 PM

I'm wondering if serializing the graph from the editor be an alternative?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

39 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

Related Questions

GetNextAnimatorStateInfo().taghash is always 0 1 Answer

Is there any good examples or tutorials of using StateMachineBehaviour properly? 0 Answers

Twiching Velocity using RigidBody.addForce. 0 Answers

VisualStudio doesn't show code helpers in StateMachineBehaviour 0 Answers

Is it bad practice to perform charcater control/movement from inside state machine behaviours? 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