Move the mouse to rotate the bobby pin into place. Press and hold W on the keyboard to attempt to pick the lock. The closer the lock goes to being fully horizontal, the closer it is to being unlocked. Hold W too long and the bobby pin will break. Unlocking will generate a new lock and an additional attempt can be made.
It turns out that trigonometry is very handy for knowing when you want to do some math on rotations and angles! It was a challenge to understand how exactly all the rotations needed to be handled to calculate a range from which the lock could be unlocked. See the credits section below for the links, but essentially the script from Zeppelin Games defines a range in degrees from the center of the lockpick's local position and allows the lockpick to be rotated along that axis. A rotation in degrees from the center of that range is generated for each new lock and is tested against the rotation angle of the lockpick when attempting to unlock. In addition to this core logic, I implemented some animations, sound effects, and managers to handle the possibility of different lock difficulties and the other gameplay designs that come along with that.
See the credits section on the itch.io page or my github for the links, but essentially the script from Zeppelin Games defines a range in degrees from the center of the lockpick's local position and allows the lockpick to be rotated along that axis. A rotation in degrees from the center of that range is generated for each new lock and is tested against the rotation angle of the lockpick when attempting to unlock.
In addition to this core logic, I implemented some animations, sound effects, and managers to handle the possibility of different lock difficulties and the other gameplay designs that come along with that.