Making a rigidbody cube snap 90 deg at a time

Hello internet.

I’ve been scouring the internet for any hint on solving this problem…no luck till thus far =(

What i’m trying to do is have a cube (rigidbody) that is suspended midair to snap 90 degrees in the direction it is bumped every time. For the love of me I just can’t seem to get it right.

Any suggestions in solving my dilemma?
Thanks in advance.

PS
If possible please keep scripts in JavaScript…though at this stage anything would be appreciated.

I assume you mean rotating 90 degrees to the side of the face it is stuck on? Then just make triggers/colliders on each quarter (or half) and give them scripts to rotate ontriggerenter.