So I was looking into how to achieve an eased rotation around the player and happened upon this page.
After about 2 hours of playing around with it, I was able to get it running. My problem is that when I press the button I assigned the level rotates several times before slowing to a stop. I was trying to get the object to slowly snap 90 degrees while keeping the same position in space. Is there anyone that can help me wrap my head around this?
var Player : Transform;
var rotateAmount = 90;
var rotateTime = float;
function Update ()
{
if ( Input.GetKey("z"))
// point, axis, amount, time
RotateObject(Player.position,Vector3.right ,90,1.0);
}
function RotateObject(point : Vector3, axis : Vector3,
rotateAmount : float, rotateTime : float) {
var step : float = 0.0; //non-smoothed
var rate : float = 1.0/rotateTime; //amount to increase non-smooth step by
var smoothStep : float = 0.0; //smooth step this time
var lastStep : float = 0.0; //smooth step last time
while(step < 1.0) { // until we're done
step += Time.deltaTime * rate; //increase the step
smoothStep = Mathf.SmoothStep(0.0, 1.0, step); //get the smooth step
transform.RotateAround(point, axis,
rotateAmount * (smoothStep - lastStep));
lastStep = smoothStep; //store the smooth step
yield;
}
//finish any left-over
if(step > 1.0) transform.RotateAround(Player.position, Vector3.right,
rotateAmount * (1.0 - lastStep));
}