Search Unity

Spawn object at realtime location (GPS)

Discussion in 'Scripting' started by alexchandriyaa, May 8, 2018.

  1. alexchandriyaa

    alexchandriyaa

    Joined:
    Jan 18, 2017
    Posts:
    140
    how to spawn prefab in different real time locations in unity2d??
     
  2. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Unity sadly is limited to a virtual world, but maybe for Unity 2019?
     
    janlucvd likes this.
  3. alexchandriyaa

    alexchandriyaa

    Joined:
    Jan 18, 2017
    Posts:
    140
    its like pokemon go in that game pokemon is spawned at different locations am asking the same
     
  4. twfarro

    twfarro

    Joined:
    Nov 23, 2013
    Posts:
    23
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    If I understand your question correctly, you're trying to place an object into the game world using real world coordinates. Something like how you can see objects on the map in a game like Pokémon Go, correct?

    You're going to need to convert between real coordinates and Unity's world space coordinates, and place the object in the game world relative to the player's position in both coordinate systems while accounting for whatever scale you're going for. There isn't a built in feature for this that I'm aware of. You'll have to do a bit of math yourself.
     
  6. alexchandriyaa

    alexchandriyaa

    Joined:
    Jan 18, 2017
    Posts:
    140
    exactly if there is any tutorials or documentation regarding kindly suggest me
     
  7. alexchandriyaa

    alexchandriyaa

    Joined:
    Jan 18, 2017
    Posts:
    140
  8. twfarro

    twfarro

    Joined:
    Nov 23, 2013
    Posts:
    23
    figure out a scale between your game coordinates and gps coordinates
     
  9. alexchandriyaa

    alexchandriyaa

    Joined:
    Jan 18, 2017
    Posts:
    140
    can you send me some examples or tutorial regarding??
     
  10. twfarro

    twfarro

    Joined:
    Nov 23, 2013
    Posts:
    23
    No, determining scale is a holistic thing, that depends on the size of the map you're rendering in-game.

    Basically you just need to figure out how many unity units correspond to some real-world distance. Use google maps to help you.

    Then you can use a remap function to convert a number (ie, a coordinate) from one scale to another

    Code (CSharp):
    1. /// <summary>
    2.     /// Remaps a given value from one range to another range
    3.     /// </summary>
    4.     /// <param name="x"></param>
    5.     /// <param name="in_min"></param>
    6.     /// <param name="in_max"></param>
    7.     /// <param name="out_min"></param>
    8.     /// <param name="out_max"></param>
    9.     /// <returns></returns>
    10.     public static float MapToFloat(this long x, long in_min, long in_max, float out_min, float out_max)
    11.     {
    12.         return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
    13.     }
     
  11. alexchandriyaa

    alexchandriyaa

    Joined:
    Jan 18, 2017
    Posts:
    140
    i think google API is updating something the new version of that is not yet released.. thank you for sharing
     
  12. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    - get the current player's gps location
    - use that as the 0,0 reference point in unity
    - set other gps points, by using the difference of the player's gps location and that point
    - use a scale variable that you will hand tune by using two real world location to offset the other gps point and match real world scale

    be careful, gps have a certain margin of error, so don't expect precise placement in the real of the meter (so more area than point). Pokemon cheat by just detecting the area you are in and spawn a pokemon to your location, it's very cheap AR.
     
  13. Monstermash28425R1

    Monstermash28425R1

    Joined:
    Sep 8, 2016
    Posts:
    9
    hi! more than one year late but, someone can tell how to parse latitude and longitude to units? i did mean, turn lat and lon to meters and then use meters as unity transform unit? how is that func, ive write some funcs with a wikipedia post but no work
     
    tpaslou likes this.
  14. JackAt360XR

    JackAt360XR

    Joined:
    Apr 16, 2021
    Posts:
    26
    Big Circle Geometry