# How do I get the direction of an object relative to the position and rotation of another object?

Okay, So I’m making a bunch of squares in 2D space that you can drag around and I want them to connect to each other when they are dragged into each other. So far all this system has been done but I’m running into a problem, the script cannot find which direction its connecting to upon dragging it to the object, I originally waited until collision and then Would take the two objects position to find out which side its collided with But this seems only to work while the object is aligned with the world. Is there any way to find which direction one object is relative to another?

Example, (Object 2 needs to know its just collided with the left side of object 1)

each box should have 4 triggered colliders (up, down, right, left)
uppon collision:

if box 2 collider with “down” collider of box 1:
box2.position = box1.position - (0, box1.length/2);

if box 2 collider with “up” collider of box 1:
box2.position = box1.position + (0, box1.length/2);

if box 2 collider with “left” collider of box 1:
box2.position = box1.position - (box1.length/2, 0);

if box 2 collider with “right” collider of box 1:
box2.position = box1.position + (box1.length/2, 0);

then, make box2 child of box 1 and make box 2 kinematik