# Vector3.RotateToward - Camera flips when revolved about origin through y = 0.

Setup: I have a simple point-click application that displays a collection of spheres in a dodecahedron shape. You can click on any sphere to bring that sphere into focus (the camera rotates about the origin toward the new point of focus).

Observe: [http://theclassicgaming.appspot.com/][1]

Note: Notice that some vertical rotations fail. In fact, there are two pair that fail and two pair that succeed. I have only a limited understanding of linear algebra, but as near as I can figure, the failure occurs when it rotates through y=0 about the z-axis. I'm sure an undefined slope has something to do with it.

Question: Have I a flaw in my math? Need I write some work-around for the particular case that fails? As of yet, I am at a loss for work-around words.

Code:

```// called when a node is clicked
private void FollowNode(WorldNode node)
{
if (node == null)
_currentTarget = Vector3.zero;
else
}

// called in update
private void AnimateCamera()
{
if (transform.position != _currentTarget)
{
Vector3 newPosition;
Quaternion newRotation = Quaternion.identity;
float rs = Time.deltaTime * rotateSpeed;
newPosition = Vector3.RotateTowards(transform.position, _currentTarget, rs, 0.000125f);
newRotation.SetLookRotation(-newPosition, Vector3.up);

transform.position = newPosition;
transform.rotation = newRotation;
}
}

```

Remark: I was planning on displaying the camera position and rotation with GUI text, but I have yet to work that part out. As I look at this more, I wonder if the problem actually lay in my use of SetLookRotation.

PS: This is what part of the alphabet would look like if Q and R were eliminated.

This is only a guess, but I wonder how it would look if you color-coded the nodes, or had a skycube, or objects in the background. Specifically, I'm thinking the "failed" rotations are actually succeeding, but the math reaches a point where the view rotates instantly upside-down. The symmetry in the model would make it impossible to tell.

If I'm right, note that the SetLookRotation has no limits on how fast it rotates. You could use Slerp to limit how fast the view spins. That's just one possible fix. Or maybe there's a safer way to change the look rotation that avoids the inversion.