1

I have many game objects with line renderers attached to it . They are roughly in the shape of rectangles . How do I go about snapping these rectangle on the edges when these objects are dragged and bought close to each other ?

I have referred to this question . But it doesn't explain how to snap at specific positions.

Here is a sample image of the objects I want to latch.enter image description here

Kitwradr
  • 1,986
  • 3
  • 18
  • 32
  • Possible duplicate of [How to align "tracks" or modular objects in Unity ?](https://stackoverflow.com/questions/50122220/how-to-align-tracks-or-modular-objects-in-unity) – Lotan Jul 25 '18 at 08:05
  • @Lotan how do I place snapping points at runtime via script (I have the coordinates) as mentioned in the link you have commented , should I create empty game objects? – Kitwradr Jul 25 '18 at 08:14
  • @Kitwadr yes, I think it's the best approach ^^ – Lotan Jul 25 '18 at 09:20
  • @Lotan what do you suggest the game object is ? A combination of a collider and a rigid body? – Kitwradr Jul 26 '18 at 05:15
  • that depends completly of your app-behaviour, but I'll suggest that the snap points do not have rigidbody, cause you don't really need it. You can play also with compound colliders, but maybe results in a mess ^^ – Lotan Jul 27 '18 at 06:29

1 Answers1

-2

There are many ways to do this task. Simply you can calculate the position of the second shape and when it's becoming closer to first with x or y axis just set their start position to first shape end position. The second way is just adding 2D colliders near the first object and simply when it triggers, move position. I will strongly recommend the first way.

  • 1
    There is nothing called start position and end position I just have a bunch of coordinates representing each polygon – Kitwradr Jul 25 '18 at 13:40