I have several models running the same animation loop. Currently they all move in unison. I would like to have each object still play the animation, but not in unison. How can I set the animation to a unique start point for a given model? Is it possible?
Hummm, no one?
Let me add more details. I have a long animation loop that is the default and only animation. That animation is run on several objects. The animation is intended to simulate some random movement. Add it to several objects and it turns into a choreographed dance routine. I’d like to start each object at a different point in the animation so each object has a different loop and no two are at the same point in the animation cycle. I haven’t seen anything about this on the web.
I Googled this yesterday but didn’t find what I was looking for, so I didn’t post back yet. I know I’ve done this before in a little tech demo I built that had a crowd in it. I’ll see if I can’t take a peek at it today and post what I had.
Yes, you can certainly do it, but (like @Schneider21 ) I don’t quite remember the details.
I bet we could dig it up from the Script Reference though, if you told us which animation system you were using (legacy or Mecanim).
If using Mecanim, for example, you can explicitly call Animator.Play, passing in a normalized time (i.e. a value from 0 to 1, indicating how far through the given state you want to jump in).
I’m guessing my version is Legacy.
private string[] animNames = {"idle", "applause", "applause2", "celebrate", "celebrate2", "celebrate3"};
public void Cheer() {
Animation[] audienceMembers = gameObject.GetComponentsInChildren<Animation>();
foreach(Animation anim in audienceMembers) {
string thisAnimation = animNames[Random.Range(1,5)];
anim.wrapMode = WrapMode.Loop;
anim.GetComponent<Animation>().CrossFade(thisAnimation);
anim[thisAnimation].time = Random.Range(0f, 3f);
}
GetComponent<AudioSource>().Play();
}
Interestingly, I don’t see the “time” property on the Animation API. That’s what makes me assume I used Legacy here. Sorry, I just opened the code file remotely from work, not actually in Unity to be able to check.
Edit: Also worth noting is that all audience members in my example are all children of the Audience manager this script is attached to.
You’re actually referencing AnimationState.time there.
And yeah, that’s how you do it in legacy. ![]()
Hey thanks,
Didn’t know Play() had parameters. Intelesense just showed Play(). Using animator.Play(“Idle”,-1,Random.Range(0f, 0.9f)) worked for me.
I guess the lesson here is always consult the docs…
