Animation System

I’m currently making animation system for group of characters.

Basically, the idea is changing the animation should be as simple as changing the state.
However, the hardest part come when 1 kind of animation can have some variations (i.e. : Idle animation can have idle0, idle1, idle2, etc animation)

my main loop to that group of object is currently look like this

function Update ()
{
	var i : int;
	if (animState == AnimState.idle)
	{
		for (i=0; i < go_pike.length; i++)
		{
			if (! (	go_pike*.animation.IsPlaying("idle1") ||* 
					go_pike*.animation.IsPlaying("idle2")) )*
_*			{*_
_*				var type : int = Random.Range(0,2);*_
_*				print(i + "'s is "+ type);*_
				go_pike*.animation.CrossFadeQueued("idle"+type, 1, QueueMode.PlayNow);*
_*			}*_
_*		}*_
_*	}*_
_*	else if (animState == AnimState.run)*_
_*	{*_
*		for (i=0; i < go_pike.length; i++)*
_*		{*_
			if (!go_pike*.animation.IsPlaying("run"))*
				go_pike*.animation.CrossFade("run");*
_*		}*_
_*	}*_
_*}*_
_*
*_

I’ve tried changing CrossFade to CrossFadeQueued, and Play.
Play can work fine, but going from run to idle will be choppy. Same goes for QueueMode.CompleteOthers for CrossFadeQueued
I’ve also tried a semaphore idea and it didn’t work really well (the loop just finish much faster than what I would intend, ergo sending hundreds CrossFadeQueued even the model is still playing. And hence, the most active animation is the most apparent one).
I probably used a wrong approach here, so if someone ever done such animation system/manager, please share me some of your insight

2 Answers

2

Looks fine (with CrossFade, not queued), except you’re not testing if idle0 is already playing, and you’re only playing idle0 and idle1.

So it actually was the case that your x velocity was 0 and as jmhoubre correctly inferred, 0/0 is NaN (not a number). That's why the internal check failed because you tried to set some internal value to NaN. It's still a mystery why you divide the same value by itself.

Well, I guess I was a bit impatient. I finally got it working by making the logic like this

if (animState == AnimState.idle)
	{
		for (i=0; i < go_pike.length; i++)
		{
			if ( go_pike*.animation.isPlaying)*
*			{	//if it's coming from other animation not of its own, then crossfade immediately*
				if(! (go_pike.animation.IsPlaying("idle0") || go_pike*.animation.IsPlaying("idle1")) )*
_*				{*_
					go_pike*.animation.CrossFade("idle"+Random.Range(0,2));*
_*				}*_
_*			}*_
_*			else*_
_*			{*_
_*				//if it's stop playing from its own animation (any idle animations)*_
				go_pike*.animation.CrossFade("idle"+Random.Range(0,2));*
_*			}*_
_*		}*_
_*	}*_
_*
*_

However, there could be some improvement on checking whether it’s coming from its animation or not (if(! (go_pike<em>.animation.IsPlaying("idle0") || go_pike*.animation.IsPlaying("idle1")) ))*
Is there a way to give some kind of wildcard to last index numbering ?

let's say I had a miscalculation