Smoothing the Rotation of an Object - Ease Out

I’ve seen a few other posts closely related to the topic, but can’t seem to find a clear solution.

Objective:
Attach this .js to a GO (Cube) that will rotate when the user swipes the screen. Instead of ending the rotation when the user ends the swipe, the cube should continue to smoothly come to a stop in the same direction it is rotating.

Here is the method for rotating the cube now:

var rotationSpeed : float = 10.0;
function Update() {

    if (iPhoneInput.touchCount == 1  iPhoneInput.GetTouch(0).phase == iPhoneTouchPhase.Moved) {
          //get Movement of finger since last update
	 var touchDeltaPosition : Vector2 = iPhoneInput. GetTouch(0).deltaPosition;
	 
          transform.Rotate(mainCam.transform.up * -touchDeltaPosition.x * Time.deltaTime * rotationSpeed, Space.World);
	  transform.Rotate(mainCam.transform.right * touchDeltaPosition.y * Time.deltaTime * rotationSpeed, Space.World);
    }

}

This rotates the cube in my scene just fine, however I would somehow like to lerp (or slerp?) the end of the rotation to give it a more “smooth” presentation.

Any suggestions?
Thanks in advance…

Maybe take a look at iTween.

well you can try to include a Slerp fct in your code then to process your rotation, or you can find some easing equation on the web and plug that in your code also.

a good resource ( which used by iTween and EZgui for some of their easing by the way …)
http://www.robertpenner.com/easing/

after this is your work to implement them in unity as you need :wink:

its actually a very simple equation…

x=x*0.8 will ease in

x=x * 1.2 will ease out

I think its something like this:

private originalPos:Vector3;
private targetPos:Vector3;

function FixedUpdate(){
var dir=transform.position-targetPos;
dir=dir.normalized; //get direction to new position
var len=Vector3.Distance(originalPos,targetPos);
var newLen=Vector3.Distance(transform.position,targetPos);
if(newLen>=len/2){
newLen=newLen*0.8;
}else{
newLen=len-newLen * 1.2
if(newLen==0)newLen=len * 0.999;// get it started
}
transform.position=transform.position+dir*newLen;
}