Moving cube like hinge at the edge of the cube

Hi,

I am trying to get animation for below. My character will be like a 3 separate cube. And it need to change shape like inside photo. I want to control animation state with keyboards.

Example: 1st state will be 3 cubes will be in straight line. Then, cube 1 can rotate at the anchor of the edge of cube 2 to achieve 2nd position. Then, cube 3 rotate to the top of cube 1 to achieve 3rd position.

I want to use all cubes in 3D. I tried with hinge joint but no luck as I can’t anchor at the edge of the cube.

Anyone can help me? Thank you

Is this a preset set of motions or a dynamic situation? i.e. can the user move any cube any direction? Off the top of my head (if it’s dynamic) I’d probably make a cube prefab, where the cube has a a child along each edge. When the user picks a direction to move, you parent the cube that you want to rotate to the appropriate child and rotate that child over a series of frames via a coroutine or a tween tool from the unity store.