In my project I want to rotate a camera along a longitude line of a sphere.
The sphere is located at (0,0,0), the camera at (0,10,0) with rotation according to inspector of (88,0,0).
This is my update function:
void Update()
{
Vector3 cross = Vector3.Cross(cam.transform.forward, sphere.transform.up).normalized;
cam.transform.RotateAround(sphere.transform.position, cross, 3.1f);
}
It’s obvious, that cross is Vector3.zero at the north or south pole, but I can “workaround” this problem by choosing suitable start (88) and step (3.1).
When running the script, the angle in inspector goes to lower values, until it reaches approximately -90. There it jumps between -88.5 and -91.5 - always half the step width around -90.
When I start with rotation (92,0,0), the shown rotation angle goes down as well but at some point it switches to 270 and then jumps around this (about 268.5 to 271.5 I guess).
In my project there are other rotations as well (along latitude for instance) and around cam.transform.forward and others, so it won’t help to change the rotation completely, since my start rotation is always the result of a couple of previous rotations of the camera around the sphere.
How can I solve this, such that I can go around the globe along a longitude always in the same direction?
Thanks!
Jeff