Animation

From ETC Public Wiki
Jump to: navigation, search

Playback

Playing an animation

 animation.Play();  // plays the default animation
 animation.Play("aniName");  // plays a specific animation

Stopping an animation

 animation.Stop(); 

Note: this rewinds the playhead back to the start.

Pausing an animation

 function Start() {
   animation["name"].speed = 0.0;
   animation.Play("name"); 
 }
 function Pause() {
   animation["name"].speed = 0.0;
 }
 function Resume() {
   animation["name"].speed = 1.0;
 }



Playing an animation backwards

 animation["name"].speed = -speed;
 animation["name"].time = animation["name"].length;
 animation.Play("name");

Note: to play forward again set the speed to a positive number and set the time to 0.0


Getting an animated object to return to frame 0 but not play

When the animation gets to the end, unless it is set to loop, it will stop at the last frame. If you use .time to set it back to time 0 or if you use .Rewind() the animation will play again.

If you want it to return to the beginning but not play then:

Add an animation event at the end of the animation calling a function:

 function AniDone() {
   animation.Rewind();   // set the time back to 0.0
   yield;                // wait until the next frame
   animation.Stop();     // stop the animation from playing
 }

OR

set the clip Wrap Mode to ClampForever

 function AniDone() {
   animation["clip name"].time = 0.0;
   animation["clip name"].enabled = true;
   animation.Sample();    // update the animation at the current state
   animation["clip name"].enabled = false;  // prevent any other updates 


YOU SHOULD BE ABLE TO => TEST THIS => This can also be used to play an animation frame by frame

 function Update() {
   animation["clip name"].time += 0.01;
   animation["clip name"].enabled = true;
   animation.Sample();    // update the animation at the current state
   animation["clip name"].enabled = false;  // prevent any other updates

Animation Events

Add here