- Home /
What's a good way to do multiple Idle animations?
I'm trying to figure out a good way to have it so my player while standing around doing nothing but his idle animation after a few minutes or seconds will perform another idle animation. Maybe even have 3 different animations that will play after each other if the player is idle for a long time. What's the best way to approach this?
Your tags are too specifics. Clic on them and you'll see that you're the only one using them, that's usually not a good sign. Try idle; animation; states
Answer by farooqaaa · Mar 23, 2012 at 01:06 PM
Here's an idea: (Warning: Untested code)
var timeForIdle : float = 5f;
var idleTimer : float;
var playIdle : boolean;
funciton Start()
{
idleTimer = timeForIdle;
}
function Update()
{
if(noInteractions && !playIdle)
{
// Frame rate dependent
idleTimer -= Time.deltaTime;
if(idleTimer <= 0)
{
idleTimer = 0;
playIdle = true;
PlayIdleAnimations();
}
}
else if(!noInteractions)
{
idleTimer = timeForIdle;
playIdle = false;
}
}
function PlayIdleAnimations()
{
if(!playIdle)
return;
animation.CrossFade("idle1");
yield WaitForSeconds(animation["idle1"].time);
animation.CrossFade("idle2");
yield WaitForSeconds(animation["idle2"].time);
animation.CrossFade("idle3");
yield WaitForSeconds(animation["idle3"].time);
}
looks like that should work I'll test it out and see :)
lol that explains my errors, not really all that good with code to begin with, any chance of a java version of this?
I have updated my answer with Javascript. Check it out.
Answer by Ziron999 · Feb 12, 2014 at 01:56 PM
No definition for noInteractions ??? C# Version:
float timeForIdle = 5f;
float idleTimer;
bool playIdle;
void Start()
{
idleTimer = timeForIdle;
}
void Update()
{
if(noInteractions && !playIdle)
{
// Frame rate dependent
idleTimer -= Time.deltaTime;
if(idleTimer <= 0)
{
idleTimer = 0;
playIdle = true;
PlayIdleAnimations();
}
}
else if(!noInteractions)
{
idleTimer = timeForIdle;
playIdle = false;
}
}
void PlayIdleAnimations()
{
if(!playIdle)
return;
animation.CrossFade("idle1");
yield return WaitForSeconds(animation["idle1"].time);
animation.CrossFade("idle2");
yield return WaitForSeconds(animation["idle2"].time);
animation.CrossFade("idle3");
yield return WaitForSeconds(animation["idle3"].time);
}
Your answer
Follow this Question
Related Questions
going back to the default state in animator 1 Answer
Idle Animations, Player Walking 0 Answers
Player plays walking animation if I press a and d at the same time while standing still 2 Answers
Why does my animation not play? idle overrules animation? 2 Answers
Animated character making mesh move when idle-animation is playing 1 Answer