Frustrating simple math

I’ve got two boxcolliders

box1: center(0,0) size.y(0,5)

box2: center(0,0) size.y(0.65)

they are both standing on a flat terrain.

I want box2 to move to box1’s position, while not sinking in to the ground.

I thought this would do it:

newTarget = new Vector2(box1.position.x, box1.position.y - (box1.size.y / 2) + (box2.size.y / 2));

I basically want box2 to slide towards box1’s position without the box2.position.y changing one tiny bit along the way. But I am getting a difference of 0.01353556 in the y-axis. And if I use different sized colliders, this difference wil get bigger, the more difference in size of the two colliders.

Can someone help me please, I think my brain just died.

Edit: just saw you can’t move along the x-axis. Instead try newTarget = new Vector2(box1.position.x, box1.position.y + (box2.width - box1.width)/2f);

Renderer myRenderer = GetComponent();
transform.position = Vector3.Lerp(transform.position,box2.transform.position, Time.deltaTime);
transform.position = new Vector3(transform.position.x,myRenderer.bounds.extents.y/2,transform.position.z);

How’s that work? You can add an offset to the y value if needed. You can also add an !isJumping verifyer/bool to check before manually setting the position to half of the renderer’s bound.extents.y.