Hello guys,
my project is to simulate a 3D environment of a specific place. I have used several assets to generate the terrains and ocean etc. for the next step I have to place some objects into my scene!I have a GeoMap of the environment and I know the place of those objects with their Latitude and Longitude! I know Unity is not a GeoBased application and in order to place these objects into my scene I have to know the position by X,Y,Z!my question is, are there any ways to convert the Lat and Long to X,Y,Z or do you guys know any possible ways to solve that problem?
thanks,
Unity’s coordinate system is unitless, so there’s no standard translation lat/long. That means the right answer is whatever you want it to be. You could just make X latitude and Z longitude or scale and offset based on the origin/center of your data or whatever you like.
If you are only covering a small geographical area then as @MakeCodeNow said you can probably just assume a flat surface. If you are covering a far larger area to the point where the curvature of the Planet is significant then this is how you would approximate it.
var centre : Vector3 = Vector3(0, 0, 0);
var radius : float = 10;
var latitude : float;
var longitude : float;
var coordPosition : Vector3;
function Update () {
coordPosition.x = radius*Mathf.Cos(latitude*Mathf.Deg2Rad)*Mathf.Cos(longitude*Mathf.Deg2Rad);
coordPosition.y = radius*Mathf.Cos(latitude*Mathf.Deg2Rad)*Mathf.Sin(longitude*Mathf.Deg2Rad);
coordPosition.z = radius*Mathf.Sin(latitude*Mathf.Deg2Rad);
coordPosition += centre;
}
bear in mind that as the radius of the earth is not constant this may vary in accuracy, to use it you will need to give it a radius, a centre point of your planet and the latitude and longitude.
Have fun!
Scribe