Check vertex position of animated object based on a reference mesh


#1

Hi Guys, let me try to explain as best as i can.

So I have a 1000 rooftop tiles resting on each other on grid (reference object)
Now I have the same 1000 tiles far away in world position. (they are animated and randomly overlapping and intersecting each other)
Is there a way I can write a script which will check the position of each tile in the reference pose and rearrange the animated tiles according to the reference object.

Lets say I have 5 tiles overlapping each other on the reference position.
Tile 1 overlapping tile 2, tile 2 overlapping tile 3, tile 3 is overlapping tile 4 and so on.
Now I have the same mesh somewhere in the world position, only this time the tiles are randomly overlapping each other.
How can I get them to overlap in specific order without intersections same as reference position.

One way I can think of is using ncloth simulation to stop them from intersecting and kind of maintaining the structure.

But what I would really like to do is write a script to keep their position based on reference object.

Any ideas are welcome.
Thank you all for your help and feedback.