Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Random Idle Blend Tree

Discussion in 'Animation' started by Zilk, Sep 9, 2015.

  1. Zilk

    Zilk

    Joined:
    May 10, 2014
    Posts:
    322
    I have been struggling with a good way to create a random idle blend tree without having several idle states.

    Right now I'm using a blend tree with 8 idles that are blended with a float. But if I'm playing Idle 1 and randomize a blend to Idle 8 it has to go through all the idles to get there. This looks quite odd at certain times.

    What I would like is to be able to have two slots in the Idle Blend Tree and switch out animation clips whenever I like. Then I could randomize a new idle, insert that clip into the blend tree and blend from last slot to that slot.

    Something like:
    animator.SetClip("StateName", int layer, int clipIndex, animationClip clip)

    Anyone got any other good solution for this?
     
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Hey Zilk - not sure if you found a good solution yet.

    A little late in replying but I have some ideas and a little related experience.
    I'm not a coder so you will have to translate common tongue into programming language. :)

    I worked on a kiosk type character creating all the animations for him to interact with the crowd and when not being interacted with perform random idle cycles.
    I collaborated with several coders to setup the system, and this was before mecanim existed.

    The best combination we found was to have a master idle cycle which was a very subtle animation that had very little movement, but a lot of micro animations like eyes looking around, eyebrows raising in relation to the eye position, corner of the mouth slightly raising, shoulder raising slightly as the character slightly rotated at the waist.
    Then I had created 42 other idle animation cycles which were grouped into common animation themes.
    We setup animation groups because there were several similar idle cycles that we didn't want to play back to back, and also others which were common that could play back to back because those animations incorporated props.
    Anyway - that's really not relevant to your situation, so -
    The idle animation cycles were pre-loaded to play directly after the base idle and they were weighted (to be selected to be played) based on a simple percentage. This randomization could be accomplished in several ways. Percentage, random number generator, etc. and then which ever animation corresponding to that number played after the base idle cycle was complete. Then the character goes back into the base idle animation. There was randomness coming out of the idle cycles also so the character could string together a list of animations (completely random) that didn't go back into the base idle cycle for several minutes.
    For your instance the random number generator could be performed twice or three times which would allow different idles to play before the character returns back to the base idle.

    The other option is to hard code the "random" cycles by having different blend sets of idles that play after the base idle has played.
    So you'd have the base idle and 3 other random idles that play back to back then it goes back to the base idle, and after the character is done he may play a different set of random idles.
    Of course this won't be random, but it could look like it to the player.

    Anyway - sorry this isn't really mecanim specific, because when we created that system mecanim didn't exist yet, but I can see a working system setup in mecanim just as we had done it before just using code.

    Hope this might give you some additional ideas towards a workable solution.
     
  3. Zilk

    Zilk

    Joined:
    May 10, 2014
    Posts:
    322
    theANMATOR2b: Thanks! I have been thinking about something similar but have not yet implemented anything (hoping that there would be some simpler solution)
     
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
  5. Zilk

    Zilk

    Joined:
    May 10, 2014
    Posts:
    322
    I found a solution for this. Creating nested blend trees and blending between the two with a float and before starting the blend just randomizing a new index for the blend tree target.

    the three variables in the first blend tree is:
    IdleIndex (controls what blend tree to use)
    IdleIndex0Random (upper blend trees variable for choosing animation)
    IdleIndex1Random (lower blend trees variable for choosing animation)
     

    Attached Files:

    RodrigoSeVeN, TonyLi and theANMATOR2b like this.