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

Question How would I make a snapping system (3D)

Discussion in 'Scripting' started by darthsae, May 18, 2022.

  1. darthsae

    darthsae

    Joined:
    May 7, 2020
    Posts:
    2
    I want to make a system where objects snap to sides. Say a cube that has snap points on all sides. A triangle with all the sided having snap points to.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
    Snapping to vertices within a shape will require you to analyze the shape by extracting the mesh vertices and aligning each object together. You're welcome to take a look at my MakeGeo project for ideas on manipulating, creating and analyzing vertices in a mesh.

    I suggest you start ultra-trivially, such as with two quads and code to extract their mesh verts and do the snapping.

    Snapping things to arbitrary locations requires analysis of all possible snap combinations, gauging distances, and then deciding "You're close enough, you snap, now adjust ALL the points of the moving shape to match."

    MakeGeo is presently hosted at these locations:

    https://bitbucket.org/kurtdekker/makegeo

    https://github.com/kurtdekker/makegeo

    https://gitlab.com/kurtdekker/makegeo

    https://sourceforge.net/p/makegeo
     
  3. darthsae

    darthsae

    Joined:
    May 7, 2020
    Posts:
    2
    Thanks I'll try that.