x


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).

more ▼

asked Aug 08 '11 at 03:27 PM

Qualdan gravatar image

Qualdan
3 2 2 4

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

1 answer: sort voted first

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).

more ▼

answered Aug 08 '11 at 03:47 PM

DaveA gravatar image

DaveA
26.5k 151 171 256

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(Mathf.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?

Aug 08 '11 at 04:32 PM Qualdan
(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

By RSS:

Answers

Answers and Comments

Topics:

x4147
x2994
x2159

asked: Aug 08 '11 at 03:27 PM

Seen: 1421 times

Last Updated: Aug 08 '11 at 04:32 PM