Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Some Coding help

Discussion in 'Scripting' started by KudoJimmy, Dec 8, 2018.

  1. KudoJimmy

    KudoJimmy

    Joined:
    Sep 6, 2017
    Posts:
    27
    Anyone has any idea how can we create a Player Spawn system similar to Ring of Elysium? A Player puts a marker on the Map. Once the game starts, Players are spawned at that exact location. I know I have to convert Map coordinates to Real 3D Coordinates and set the transform, But I want to ask if anyone know how to do it. I tried a lot but failed..
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    3,437
  3. KudoJimmy

    KudoJimmy

    Joined:
    Sep 6, 2017
    Posts:
    27
    Yes. But that thread got all about my other problem so i thought to start clean. And I am still having this problem. On scene start i am showing a map, now when user clicks on it, a marker is created. I get the Marker's transform. Everything good until this. Now, how to convert that coordinates to real world. For eg, on map if user marks location X on map, he spawns there. If he puts mark on a hill next to location X he spawns there. I dont want to make it static by giving spawn points in dropbox or something. I want to make it dynamic. User can choose to land any where he wants. Even in the water surrounding the map. Can you give me an example how can I convert it?
     
  4. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    3,437
    I explained it to you on your other thread.
     
  5. KudoJimmy

    KudoJimmy

    Joined:
    Sep 6, 2017
    Posts:
    27
    Yes but sorry I am not able to convert it into useful piece of code. Theoritically, in my mind your explanation was perfect. But idk how to imolement it using c#.
     
  6. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    3,437
    Then please, explain to us what have you tried, post your code. We won't write your code for you. You need to work on it. Also feel free to google for problems you're facing.
    But I think you're over-complicating things. If you have the point on your 2D image and you know the dimensions of the image you can calculate the relations between these (coordinate X and width, and then coordinate Y and height). After that you apply the same relative coordinates to your world (if the coord X was 23.134323% then calculate the same when you know the dimensions of your world). It's basic math.

    And do it step by step, first, just calculate the coordinates and put the player there no matter what. Then, if you want to avoid mountains, you need to find a way... maybe raycast the place and use the Z coordinate of that hit point, so you can put the player on the surface... after that, if you want to avoid the water, you need find a way, so maybe you put empty colliders around the water and if the raycast hit them you tell the player that it's an illegal move or whatever.
    Don't try to make everything right for the first round, move step by step, break down your task into smaller pieces, otherwise you will never be able to create a piece of software alone.
     
  7. KudoJimmy

    KudoJimmy

    Joined:
    Sep 6, 2017
    Posts:
    27
    Yes. This hint will be more useful to me. I never wanted anyone to write for me nut like you did, people can help me understand basic logic. I will try thi tomorrow.. its late night..

    I have not scripted anything regarding this .All what I did was get coords on map and on real life and tried to see if theres any correlation or similar pattern using which I can create a formula for that. But I did not find any thing use ful. Like you said, converting it from Dimensions, i will try it first thing tomorrow. Also, judt to be clear, If my Canvas is 1366x768 and the point on map is 307,127,0 then I should compare percentage from 307-1366, and 127-768 right? I will calculate z from raycast.. am I correct?
     
  8. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    3,437
    Yes, but it depends on how you built your world. In Unity the 3D coordinates are XZY by default (which means by default x is left to right, z is back and forth and y is down to up), so you will need to apply your Y coordinate from the image to the Z coordinate of the world and get the Y coordinate from raycast. (Just take a look at the editor coordinate arrows in the scene view's top-right corner)
     
  9. KudoJimmy

    KudoJimmy

    Joined:
    Sep 6, 2017
    Posts:
    27
    Okay.. Thank you very much.