Search Unity

World hit Boxes

Discussion in 'World Building' started by Jackgriller, Sep 26, 2021.

  1. Jackgriller

    Jackgriller

    Joined:
    Sep 26, 2021
    Posts:
    1
    Hello Everyone I am Super new to Unity and I have been looking around and can not find my answer please can someone help me.

    I am trying to create a planet with Grids line on them, and those line cross to make boxes. the boxes light up when hover mouse over it with Raycasting. I want to know if it possible to create 10 trillions boxes?. Those boxes when light up you can click and add picture to it or something attach to those boxes so player can open it to earn reward.

    I have attach a picture sample please I really need help with this one. Thank you
     

    Attached Files:

  2. NocturnalWisp

    NocturnalWisp

    Joined:
    Oct 2, 2019
    Posts:
    62
    10 trillion? That's nuts o_O However I think it could be done with some very important optimization, and behind the scenes magic. (Avoid creating actual boxes for every location.)

    There could be many solutions to the problem, but I'll let you in on my thoughts. Let's start from the beginning.

    I would first create a sphere with an earth texture on it. I would have it have a sphere collider. Then I would create a script on the camera that shoots a ray from the camera to the mouse position. (https://docs.unity3d.com/ScriptReference/Camera.ScreenToWorldPoint.html)

    The point that is returned would be the point on the sphere that I want to find the "cell" of. To find this cell, I would need to a bit of math (not great off the top of my head) to get the cell position. Likely using something similar to how https://docs.unity3d.com/ScriptReference/GridLayout.WorldToCell.html works.

    Once I have this cell I can add whatever I want at that location.

    I'm not 100% sure why you need the grid layout when you can select any position and add something to that location; but if you do, check out how grids work and converting world points to cell points.

    Being super new to unity, I suggest you look into simpler tutorial projects. If you are in a rush you can check out Sebastian Lague on YouTube. He's done a number of videos on planets and spheres in general.

    I hope this was a helpful explanation, if you need more details don't fear asking, though I don't work with tiles very much. (cause I don't like them :p)