- Home /
Rotate camera smoothly down and back up
I'm trying to get a camera in my scene to smoothly rotate down (something like 10 degrees) and then back up to its original position (like a security camera).
I think Mathf.Lerp is probably the way to go, but I can't figure how to stop at the determined place and then get back up.
It should only do this when specifically activated (by a keypress or another function). And before rotating, a Boolean value should be turned true and when finished, it should turn false (this would allow my other functions to notice the rotation is happening and not interfere with it).
Answer by DaveA · Aug 08, 2011 at 03:47 PM
If you don't mind using the Animation Editor, this would be easy to do that way, and you could even insert events at the start and end to set that boolean for you.
But you could also use Transform.Rotate http://unity3d.com/support/documentation/ScriptReference/Transform.Rotate.html Several ways to do it, you could have a coroutine which yields while it's going down, then sets the up direction and yields again, or you can have limits you check in an Update function ('current angle' vs some lower and upper limits).
Thank you for the answer. Transform.Rotate is the one I used to rotate it down (probably should have mentioned that), but that's as far as I got: transform.Rotate($$anonymous$$athf.Lerp(startAngle, endAngle, Time.deltaTime), 0, 0);
I haven't used coroutines before (I’m relatively new coder), so I don't think that's an option right now. But how would I compare two rotations to each other? Could you give me a code example?
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
move the object where camera look 0 Answers
How to make an object face the mouse in a non-2D world 1 Answer
Problem with Camera rotation script 3 Answers