how to move object with joint

I have 2 cubes.
The cube1 moves (left and right)
The cube2 moves ^V (up and down)
If cube1 moves, cube2 also moves.
if cube2 moves, cube1 doesn’t move.
Now I want that that cube2 moves like a fixed joint over the x-axis. but it still needs to be able to move up and down. How is this possible?

Edit:

can the problem occur because my movement is based on transform instead of rigidbody?

in the Inspector simply Lock the axes you don’t want to move.

I based my movement on rigidbody.velocity and took and Configurable joint instead of a fixed joint.