A simple, powerful and easy to use animation system for Unity. Focusing on the established solutions and frameworks of projects such as TweenLite, Tweener, and other tweening systems, iTween is a battle-tested solution for streamlining production in the Unity environment.
Developed by Bob Berkebile (pixelplacement.com). C# port by Patrick Corkum (insquare.com). Thanks to: Bully! Entertainment, Robert Penner, The Unity development team, the Tweener team, GreenSock, my Wife, my Son, my Parents (thanks for all the testing Dad!), all of the contributors on the unify community wiki and everyone I forgot to mention who's hard work ended up integrated into this project.
The easiest part; download it and plop it in! iTween is a static class (you don't HAVE to know what that means), so just copy it ANYWHERE in your project structure and it's "installed" and ready to work.
iTween has a few key methods you can call to make the magic happen. Each of these "tools" accept parameters you can use to make an animation behave exactly the way you want. Let's move an object along the x-axis from it's current position to a new coordinate of 1.7 over the span of 2 seconds:
iTween.moveTo(gameObject,{"x":1.7, "time":2});
In adddition to single simple movements, iTweens can be chained together using the "delay" property. The only limitation is your imagination and your ability to remember how much the "delay" count should be.
private var go : GameObject;
private var cam : GameObject;
function Awake(){
go = gameObject;
cam = camera.main.gameObject;
}
function Start(){
iTween.rotateFrom(go,{"y":90, "time":1.5, "transition":"easeInExpo"});
iTween.moveFrom(go,{"y":3.5, "time":1.5, "transition":"easeInExpo"});
iTween.colorTo(go,{"r":3, "g":.5, "b":1.2, "time":.3, "delay":1.5});
iTween.shake(cam,{"y":.3, "time":.8, "delay":1.5});
iTween.scaleTo(go,{"y":2, "time":2, "delay":2.3});
iTween.rotateBy(go,{"x":.5, "delay":4.3});
iTween.moveTo(go,{"y":1.2, "delay":4.6});
iTween.moveTo(go,{"y":0, "delay":5.8, "transition":"easeInExpo"});
iTween.shake(cam,{"y":.3, "time":.8, "delay":6.8});
iTween.colorTo(go,{"r":.165, "g":.498, "b":.729, "time":.5, "delay":7.6});
iTween.scaleTo(go,{"y":1, "delay":7.6});
}
In addition to the linear path movement of moveTo, moveFrom, moveBy, moveToWorld, moveFromWorld, and moveByWorld you can also move objects on curved paths using moveToBezier and moveToBezierWorld. Each Vector3 you add to the bezier argument adds another "control point" for the object to curve in and out of. You can add as many points as you want to the path. Special thanks to David Bardos for this functionality and Patrick for fixing things up (as always!).
By default objects will orient themselves to the path they are traveling on but you can turn it off by setting "orientToPath" to false. In addition you can also pass in a Vector3 for a "lookAt" argument for some cool effects (think dramatic camera movements!).
If you'd like the sample shown here (which shows a pretty advanced method for getting control points into moveToBezier) grab it here! (Note: The version of iTween in this project will not be updated as new versions are released!)
For example (I assure you it only "looks" complex):
function Start(){
iTween.moveToBezier(gameObject,{"time":3, "transition":"easeInOutQuint", "bezier":[Vector3(0,1.5,0), Vector3(0,0,1.5), Vector3(0,-1.5,3), Vector3(1.5,0,3), Vector3(1.5,0,0), Vector3(-1.5,0,0)]});
}
Nearly all of the methods in iTween allow the addition of an optional "onStart", "onUpdate" and "onComplete" argument. These arguments takes a string reference to an existing function in any script attached to the currently utilized GameObject. In addition, you can optionally provide "onStartParams", "onUpdateParams" and "onCompleteParams" arguments to allow the passing of an object to the destination "onStart", "onUpdate" or "onComplete" functions. You can also specify "onStartTarget", "onUpdateTarget" and "onCompleteTarget" to allow the firing of a function on a different GameObject.
To illustrate this functionality let's create a looping animation (Note: iTween includes a native loop feature called "loopType" built in which could have been set to "pingPong" to do this in 1 line of code but this example is merely to demonstrate the flexibility of utilizing callbacks):
private var tweenTarget : GameObject;
var counter : GUIText;
var count : int =0;
function Start(){
tweenTarget=gameObject;
roll("right");
counter.guiText.material.color = Color.black;
}
private function roll(direction: String): void{
switch(direction){
case "right":
iTween.rotateBy(tweenTarget,{"z":-.5});
iTween.moveTo(tweenTarget,{"x":1.7, "onComplete":"roll", "onCompleteParams":"left"});
count+=1;
break;
case "left":
iTween.rotateBy(tweenTarget,{"z":1});
iTween.moveTo(tweenTarget,{"x":-1.7, "onComplete":"roll", "onCompleteParams":"right"});
count+=1;
break;
}
counter.text=count.ToString() + " Loops";
}
A very quick and simple version of "Simon" powered by iTween (and thrown together in 3 hours). Sorry for the lack of comments and for the record I HATE this style of game... it always made me nervous. (Note: The version of iTween in this project will not be updated as new versions are released!)
Download it here!(Note: This was built with regular Unity and may need some adjustment to work on iPhone Unity)
Each method in iTween has an accompanying set of default arguments to help alleviate coding repetition. You can augment each method's default arguments at any time to avoid duplicating tedious typing, make global animation changes, or just feel powerful.
The available defaults names are as follows:
Let's change the default transition for "moveDefaults" which effects every "moveTo" and "moveFrom" method:
//Change a default:
iTween.moveDefaults["transition"] = "easeInOutBack";
//Leverage new default (notice we don't specify the use of a transition):
iTween.moveTo(gameObject,{"x":1.7,"time":2});
While nearly every method in iTween is meant to be called once and then finished, there are a few methods that are designed to be called continuously from Updates or similar repetative techniques.
For example, you can easily cause a camera to smoothly follow an object by using lookToUpdate:
var target : Transform;
function Update () {
iTween.lookToUpdate(gameObject,{"target":target.position, "lookSpeed": 3});
}
Click on each method name to get more information.
iTween.audioFrom(GameObject, Hashtable)iTween.lookToUpdate(GameObject, Hashtable) - REPEAT CALLABLE
iTween.lookToUpdateWorld(GameObject, Hashtable) - REPEAT CALLABLE
iTween.moveToUpdate(GameObject, Hashtable) - REPEAT CALLABLE
iTween.moveToUpdateWorld(GameObject, Hashtable) - REPEAT CALLABLE
iTween.punchPosition(GameObject, Hashtable)
iTween.punchPositionWorld(GameObject, Hashtable)
iTween.punchRotationWorld(GameObject, Hashtable)
iTween.punchScale(GameObject, Hashtable)
info(at)pixelplacement.com - I wasn't cool enough to be able to pull off an email form :(
If you find iTween useful... buy us a 6-pack!