How do i make a grid around a spherical object that has longitude/latitude coordinates

I have a model of the moon and i am trying to make a grid that shows the longitude / latitude on the moon depending on the position of your cursor, i already have a moon with a camera that can rotate around it, i literally cannot find any information on how to make a coordinate system of longitude /latitude around a spherical object

They’re just angles measured from the center, just figure out the spherical coordinates and it’s not more than that.

This file makes a sphere as procedural geometry.

See line 65 for how it uses latitude and longitude (computed in line 63 and line 58) to produce the point.

All angular computations are in radians, but you can multiply by Mathf.Rad2Deg to obtain degrees.

If you just need to spin a camera spherically around an object, you don’t need any of the above noise. Just make a hierarchy of two tranforms, one to rotate longitude, one to rotate latitude, and adjust those .localRotations, either of the camera, or of the moon itself, depending on how you want it to work.

1 Like

hey thank you for this but i have no idea how to use this, where exactly should i paste this code in and is there any way to display the longitude / latitude on the screen depending where your cursor is because i have no idea if the program is working right now, i just added a C# script as a component to the moon model and pasted the script you sent me, sorry for the hassle

That’s not a thing… I was providing an example of the computation. :slight_smile:

Sounds like you might want to back up a bit and do some basic tutorials for displaying quantities onscreen. Nothing anyone can type in this little box will capture all the myriad code and scene setup you need. The easiest is to use the UGUI system, which is the UnityEngine.UI namespace and is installed via the package manager.

yeah i figured but its alright i already figured it out , thank you for trying to help anyway!

If you have a lat long sphere with a rectangular texture you could just use the uv coordinates returned by your raycast and calculate them into lat/long. So for example longitude could be (v * 360 ) - 180. Something like that should be sufficient if you have setup your mesh properly.

1 Like