mapbox-unity-sdk icon indicating copy to clipboard operation
mapbox-unity-sdk copied to clipboard

When moving in the real world, how to convert speedmeterspersecond into pixels in the unity world?

Open wei-kris opened this issue 3 years ago • 5 comments

When moving in the real world, how to convert speedmeterspersecond into pixels in the unity world?

I don't know how many pixels are moved in the unity world by moving one meter in the real world?

Thanks.

wei-kris avatar Mar 12 '22 13:03 wei-kris

found this some time ago in a thread:

///<summary>
    /// Temporary hack to calculate the multiplicator which needs to be applied to spawned gameobjects
    /// to match the actual tile size.
    /// </summary>
    /// <param name="targetPlayerPos">WorldSpace Position</param>
    /// <param name="map">Mapbox Abstract Map Instance</param>
    /// <returns>Worldscale Unit conversion</returns>
    public static float GetOneMapMeterInUnityMeters(Vector3 targetPlayerPos,AbstractMap map)
    {
        // hackish way of doing the conversion, since there is no obvious way of doing it in the API
        // taking a position X meters away, converting to map coords, and then back into unity world coords.
        var playerPosGps = map.WorldToGeoPosition(targetPlayerPos);
        var playerPosInMeters = Conversions.LatLonToMeters(playerPosGps);
        var playerPosInMeters1MeterAway = playerPosInMeters + new Vector2d(1, 0);
        var oneMeterAwayLatLon = Conversions.MetersToLatLon(playerPosInMeters1MeterAway);
        var worldPosOneMeterAway = map.GeoToWorldPosition(oneMeterAwayLatLon);
        var oneMapMeterInUnityMeters = (worldPosOneMeterAway - targetPlayerPos).magnitude;
        return oneMapMeterInUnityMeters;
    }

Markovicho avatar Mar 16 '22 08:03 Markovicho

@wei-kris did this solve your problem ?

Markovicho avatar Mar 23 '22 08:03 Markovicho

@Markovicho Thank you. I got a number of 0.7664185. Does this mean that 1 meter is equal to 0.7664185 unity unit?

image image

wei-kris avatar Mar 25 '22 09:03 wei-kris

image

WorldScale : Map is rendered at actual scale, unity to mercator conversion factor is ignored. I originally thought that when I used this option, the ratio of unity world to real world was 1:1

wei-kris avatar Mar 25 '22 09:03 wei-kris

@wei-kris if you need precision, I think best approach would be converting latlng values and calculating great circle distance formulas directly. Unity visualization will always be off, sometimes quite a lot due to the effect of latitude not being calculated properly.

brnkhy avatar May 17 '22 09:05 brnkhy