- Home /
 
 
               Question by 
               Keeinor · Feb 24 at 04:12 PM · 
                rotationrotate object  
              
 
              Rotate sphere, so that any fixed point on the sphere points at the camera.
Hello all!
My question is as follows, I have a sphere (earth), and I want to rotate it so that any fixed point of my choice on the sphere points directly at the camera.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by homer_3 · Feb 24 at 04:44 PM
If you are able to get the exact point in space of the sphere that you want to look at the camera, I think this should work
 Vector3 toPoint = (spherePoint - sphere.transform.position);
 Vector3 toCamera = (camera.transform.position - sphere.transform.position);
 Quaternion rotateBy = Quaternion.FromToRotation(toPoint, toCamera);
 sphere.transform.rotation = rotateBy * sphere.transform.rotation;
 
              Thanks for the reply, that method works great on some points, but not all points.
Would you happen to have an alternative way? or any reference I can follow?
Quaternion math is tricky since it's not communicative. I just tested it out and on the last line, you just have to multiply in the opposite order. So it should be sphere.transform.rotation = rotateBy * sphere.transform.rotation;
Your answer