smooth rotation / movement ?

i am making a 2D game that has 3d rotation with camera i can make it rotate and change axis but i want to make it smoothly transition how can i make smooth rotation ? and smooth movement ? this is how i do it :- transform.Rotate(0,-90,0); i want it to be smooth and in movement there is Distance from player i change the distance from X 10 to X = 0 and Z 0 to Z = 10 but all happen instantly how can i fix this ?

more ▼

asked Oct 08, 2011 at 11:10 AM

avatar image

95 23 24 26

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Smooth in Unity means Lerp! (Slerp, for Quaternions) You should use the "Lerp filter", a smart use of Lerp that behaves like a smoothing filter. Attach this script to the camera:

var speed: float = 2.5; var cameraAngles: Vector3; // the target angles around x, y and z var cameraPos: Vector3; // the target position

function Start(){ cameraAngles = transform.eulerAngles; cameraPos = transform.position; }

function Update(){

 transform.position = Vector3.Lerp(transform.position, cameraPos, speed*Time.deltaTime);
 var newRot = Quaternion.Euler(cameraAngles); // get the equivalent quaternion
 transform.rotation = Quaternion.Slerp(transform.rotation, newRot, speed*Time.deltaTime);

} You just set the angle and position you want in cameraAngles and cameraPos, and the camera goes smoothly to the new rotation/position.

more ▼

answered Oct 08, 2011 at 11:28 AM

avatar image

61.1k 54 205 356

thank you.

Oct 08, 2011 at 01:25 PM midomido
(comments are locked)
10|3000 characters needed characters left


I don't exactly understand what you mean, but have a look at Quaternion.Slerp() for smooth interpolation of rotation and for translation Vector3.Lerp().


more ▼

answered Oct 08, 2011 at 12:13 PM

avatar image


(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Oct 08, 2011 at 11:10 AM

Seen: 11260 times

Last Updated: Aug 02, 2012 at 02:17 AM