# How To Slow Camera Position Transform?

The main camera changes position when triggered but, too quickly. Is there a way to "slow" the cameras journey to it's new position? Thanks for looking.

var MainCamera : Camera;

var CurveX = 90.0;

var CurveY = 45.0;

var CurveZ = 145.0;

function Update () { }

function OnTriggerEnter (other : Collider) { Camera.main.transform.position = Vector3(CurveX, CurveY, CurveZ); }

Try this:

``````var CurveX = 90.0;

var CurveY = 45.0;

var CurveZ = 145.0;

var increment:float;

var moveCam:boolean = false;

function Update () {
if(moveCam){

Camera.main.transform.position = Vector3.Slerp(Camera.main.transform.position,Vector3(CurveX, CurveY, CurveZ), increment);

if (increment <1)
increment +=0.01;

}

}

function OnTriggerEnter (other : Collider) {

moveCam = true;
}

``````

Slerp/Lerp function will smoothly change values.

Check this also:

http://unity3d.com/support/documentation/ScriptReference/Vector3.Slerp.html

Thanks for the reply Kourosh but, this code does nothing. Increasing/decreasing the increment values also has no effect on the camera. I tried adding a camera/target variable like in my original code but, again no difference. So, I changed it around a bit.

I swapped Slerp to Lerp and replaced the increment modifier with Time.deltaTime. This setup works better than my original code in that the camera movement is slowed but, still not slowed enough.

I'm a little confused on Time. It's my understanding that Time.deltaTime is an action done within a certain amount of time were-as Time.time is an action done within a certain amount of frames - is this correct? Either way, no matter how I +,-,*,/ the Time factor - the amount of time it takes the camera to "move" to it's new position seems to be the same. (though * and / seem to add/subtract distance rather than time)

Here is my modified code as it is now.

``````var MainCamera : Camera;

``````

var CurveX = 90.0;

var CurveY = 45.0;

var CurveZ = 145.0;

var duration = 1.0;

function Update () { }

function OnTriggerEnter (other : Collider) { Camera.main.transform.position = Vector3.Lerp(Camera.main.transform.position,Vector3(CurveX, CurveY, CurveZ), Time.deltaTime + duration);

}

Time.deltaTime + duration does not seem to make the position transition any longer. If anyone could tell me what it is I am doing wrong - it would be greatly appreciated. Thanks everyone for your comments and interest.

I find that I have to do a lot of smoothing from code and don’t want the overhead of adding an iTween to the game object.

To help I’ve built some helper classes which you can take a look at and download here. Basically they let you replace a standard float, Vector3 or Quaternion with a SmoothXXXX version that will use one of four smoothing functions to interpolate between the current and the target position over time.