Is it possible to make floor constraint base on surface detection?
Try changing the origin of the cube to any vertex on the bottom of the cube:

Select the vertex in edit mode.

Press ⇧ Shift + S to get the cursor menu and then choose Cursor to Selected.

Then in object mode get the object menu and set the origin to the cursor.