Roll/rotate a cuboid at its edge

Hello there

I have a cuboid (a cube width 1 unit width and 2 units height), and I want to roll it/rotate it around a pivot point at its edge.

When I click the left arrow button, the cuboid should rotate around the bottom left edge and when I press up arrow, it should rotate on the bottom edge longest away from the camera. The behavior should be like in this game - https://www.youtube.com/watch?v=eaBTCCZNjSY

I have an image which may illustrate what I mean
59847-ofnpy.png

My problem is how I can rotate around the cuboids edge, and then reset the pivot point to the center of the cuboid afterwards. Please help me, since I can’t figure out how to solve this problem at the moment.

Work with different empties (5; one at each edge, one in the middle) you can use as pivot point/axis point.

Duplicate question:

Sor similar questions see this.