- Home /
Rotation without tilt around a globe.
So i have a bad rotation week as i am doing little bit more "advanced" 3d rotations for first time in my life. So i have our planet earth in a 3d globe, rotating to a point where the mouse was clicked thanks to robertbu helping me out with the Quaternions.The problem here is that with Quaternion.FromToRotation i am getting the planet tilted at some clicked points. Is it possible to avoid the tilt?
If I understand correctly, just assign 0.0 to the 'y' in hit.point before calling FromTo ().
Answer by Bunny83 · Aug 08, 2014 at 11:33 PM
I have a quite old sample project on my dropbox here. At the bottom it has a link to the demo package. From your description it's hard to tell what you exactly want to do and what you are doing and what's actually wrong. A graphic / screen shot or the code your using would help to understand your problem.
edit
I've found the old question to which this sample is related to:
http://answers.unity3d.com/questions/142461/centering-to-main-camera-a-clicked-point-on-sphere.html
Just to clarify a bit: FromToRotation rotates around an arbitrary axis / plane depending on the two given vectors. it's just a relative rotation and doesn't take into account any kind of coordinate system. If you want the typical geographic coordinate system you should work with lat and lon angles.
Yes that is the thing i needed man thanks!Never knew it can be much more complicated than a simple rotation.
Hmm this works just fine when the sphere's starting rotation is not modified.Is it possible to calculate the current latitude and longitude with already modified rotation?
I'm not exactly sure what you mean by modified. If you mean that at Quaternion.identity you don't have 0°, 0°, then the easiest solution is to parent your sphere to an empty gameobject and rotate the sphere locally to align "0°, 0°" with the identity rotation of the parent. Now when you rotate the parent it should be correct. Otherwise you can of course manually store the initial rotation and multiply the generated rotation (from lat / lon) by your initial rotation. $$anonymous$$eep in $$anonymous$$d that Quaternion multiplication isn't commutative, so you might need to reverse the order.
@parndepu:
That's strange. I just downloaded the package and yes, it seems Unity can no longer properly load old unitypackages. I recreated the test scene in a newer Unity version, updated the script (collider property is now deprecated) and created a new package.
However unfortunately it's not possible to get the same look as in my original demo as Unity has changed it's default sphere mesh. It's no longer a mercator like mesh but a morphed cube mesh. The UV unwrap still tries to mimic the mercator projection but it's a bit distorted at the poles. (Of course distorted beyond the distortion that comes with the mercator projection ^^). Furthermore the unwrap is rotated 90° so the longitude is off by 90°.
You most likely don't want to use Unity's new sphere for a mercator texture. You should create a sphere in a modelling program and import that mesh into Unity.