Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Need Help Creating Spherical Grid

Discussion in 'Scripting' started by DonnyTech, Sep 8, 2014.

  1. DonnyTech

    DonnyTech

    Joined:
    Jan 7, 2014
    Posts:
    9
    Okay, so I'm not sure if this is the right thread for this but oh well.

    So basically I'm working on a game in which you will be able to place buildings onto a planet. The only problem is that I need to be able to have the buildings snap to the planet, and rotate away from the planets origin point (so that the buildings are flush with the planets surface).

    Is there a simple way to do this, or do i need an advanced script?
    Also, could I simply make the faces of the planet act as grid spaces (the planet is low poly so the faces are quite large)?

    I use C# BTW.
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Aligning to a sphere is easy, just match the objects up vector to (objectPosition - sphereCenter)
    As for making the surface a grid, that is not easy, theres no 'perfect' solution for mapping a grid to a sphere
     
  3. DonnyTech

    DonnyTech

    Joined:
    Jan 7, 2014
    Posts:
    9
    Could I perhaps just ditch the grid entirely, and just make the buildings allign/stick to the planets surface?
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    For a start, you can probably use
    Code (csharp):
    1. building.rotation = Quaternion.FromToRotation(Vector3.up, raycastHit.normal);
     
  5. DonnyTech

    DonnyTech

    Joined:
    Jan 7, 2014
    Posts:
    9
    I have a feeling that I need to do a lot more research as far as rotation and vectors go lol. Thanks for the help guys, but I'm not getting anywhere until I learn what all of this stuff does. Can anyone point me towards a good resource to learn about this kind of stuff (rotation, vectors, inheritance, etc.)? I am very new to C# and programming in general :D