- Home /
Orbit 2D camera around circle but keep lookat towards z axis
Hello,
I have a 2D circle in my scene, and buttons around it evenly positioned at certain distance from center of circle.
The problem: I want to do a script where Ortho camera rotates around circle from one button towards next, Lerp motion, traveling left or right depending on keypress.
I cannot figure out how to do this. I have a picture to show what Im trying to do. In it the 1 and 2 are buttons (though I may have any number), the rectangles are camera positions, and all the lines are the positions camera can stop at:
Any help appreciated!
Answer by MartinCA · Oct 12, 2014 at 05:21 AM
Calculate the camera position using X = r x cos(a) Y = r x sin(a)
Where r is your orbit distance and a is your current orbit angle, you can then interpolate a for circular motion.
For rotation, simply set your rotation around z to a.
Also, keep in mind Mathf.sin/cos work with radians / if you want to use angles there are constants in Mathf you can multiply by to convert your value. Also, the above solution would position a=0 on the right hand side (x=r, y=0) - but you can always swap the sin cos functions to change that behavior.