- Home /
Rotating A Camera Back and Forth
Hello! So as the title says I want to rotate a camera back and forth along its z axis. I don't want to use iTween because I already tried that but it turned out kind of weird. Anyways, I made this script that I thought would work but it will only bump back my camera only once then it keeps rotating the other way forever. Here's the script:
private var left = false;
private var right = true;
function Update ()
{
if(left)
{
transform.Rotate(0,0,3*Time.deltaTime);
}
if(right)
{
transform.Rotate(0,0,-3*Time.deltaTime);
}
if(transform.localEulerAngles.z > 4 && transform.localEulerAngles.z < 350)
{
left = false;
right = true;
}
if(transform.localEulerAngles.z < 356)
{
left = true;
right = false;
}
}
So if you have any ideas how to make it keep bumping the camera around it would be great!
Answer by Lovrenc · Jan 16, 2013 at 03:20 AM
What about something like this:
function Update ()
{
transform.rotation = Quaternion.Euler(0,0, Mathf.Sin(Time.realtimeSinceStartup) * 70);
}
To get broader angle change the constant. If you want it to swing faster you can update to:
transform.rotation = Quaternion.Euler(0,0, Mathf.Sin(Time.realtimeSinceStartup * 2) * 70);
Your answer
Follow this Question
Related Questions
Transform Rotation - Maths Problem 2 Answers
Irregular position when instantiating clone during camera rotation? 1 Answer
How do I have a Child tell a Parent to move without the Child itself moving 0 Answers
How do I implement orthographic elements into a perspective camera? 0 Answers
How do i lock the position of the camera above the player relative to the origin point? 0 Answers