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 ?
Answer by aldonaletto
Oct 08, 2011 at 11:28 AM
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
cameraAngles = transform.eulerAngles;
cameraPos = transform.position;
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.
Answer by torsten
Oct 08, 2011 at 12:13 PM
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().
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
To help users post good questions and use the site effectively we have posted a user guide. Please check it out.
Answers and Comments
4 People are following this question.
Undesirable character flipping
how to stop a player moving thought the walls in a 2d game
How do I rotate my camera smoothly?
Set Character's Rotation