I have a game object that is a globe. I am trying to place a new game object at coordinates of latitude and longitude. Is there an easy way to convert latitude and longitude to Vector3 coordinates?
I’m no expert, but as far as I know lat and long are just degrees around the globe. So you should be able to find the position around a sphere by rotating a “zero” direction by those degrees, then multiplying by the sphere radius to reach the surface in that direction.
Try this example component, which will draw a sphere gizmo at a longitude and latitude around a designated center transform position. The center transform’s X axis is used as the “zero” direction, or when lat & long are 0.
using UnityEngine;
public class GlobePositioningExample : MonoBehaviour
{
public Transform center;
public float radius = 1;
[Range(-90, 90)] public float latitude;
[Range(-180, 180)] public float longitude;
private Vector3 newDirection;
public void OnDrawGizmos()
{
if(center != null)
{
newDirection = Quaternion.Euler(0f, longitude, latitude) * center.right;
Gizmos.DrawSphere(center.position + (newDirection * radius), 3);
}
}
}
Just remember that Unity is Y up and not Z as on wikipedia.
I know we had an asset that did this, but it didn’t use a globe. It was a flat plane.
Unity also just introduced it’s wrld api Unity Blog
I don’t know if you can get into the code, but if you can, it may provide some insight.
This thread might help: Rotate sphere to look at camera based on lat lon - Unity Engine - Unity Discussions