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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Object snapping to Sphere in-game for planet citybuilder

Discussion in 'Scripting' started by LifeSymbiont, Mar 12, 2022.

  1. LifeSymbiont

    LifeSymbiont

    Joined:
    Apr 19, 2015
    Posts:
    36
    Hello.
    V in untiy allows vertex snapping, snapping objects to the vertex positions of other objects.
    I want to make a planetary city builder game where buildings can be placed on the vertexes of a textured sphere. With the V key, I can do so in the normal editor, but I don't know how that would work at runtime.
    How can I do this kind of snapping functional in game / at runtime?
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    You can get a list of vertices through mesh.vertices. You'll probably need to transform them into world space.
     
  3. LifeSymbiont

    LifeSymbiont

    Joined:
    Apr 19, 2015
    Posts:
    36
    Thank you for the idea! So, how would I write it that my objects align to the position of the list of the world space mesh.Vertices?
     
  4. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    You can read the mesh.normals to get their "directionality", if that's what you mean.