GitHub Project

So after playing Fallout 4, I decided to recreate the lock-pick mini-game in Unity for fun. Personally, I don’t find the mini-game very fun, but implementing the logic behind it seemed easy and interesting so I wanted to give it a shot. I thought it would be a nice reference for others as well so I decided to make it available on github.

I first modeled out the assets, since they were simple enough I didn’t feel like using placeholders.

The first interesting problem I faced was keeping the lock-pick in place as the cylinder rotated. I couldn’t simply parent the pick to the cylinder, because then the cylinder would rotate with it. One option would be- creating a dummy object child of the cylinder at the location the pick should stay, and then copying the dummy position into the pick’s position every update. A better solution would be to create a component that handles the logic for us without any special dummy objects. The LinkConstraint component does just that. This component recreates the parent child relationship of objects without having to actually parent an object. It allows us to inherit position and/or rotation. So, with this component, we can simply link the pick to the cylinder, don’t inherit rotation, and voila—all done.

The next important task to tackle is the handling of the cylinder and pick rotations. The easiest but least dynamic solution would involve merely updating the object’s rotation in code, based on player input. However, it would be better to allow an animator to dictate the exact locomotion of the pick and cylinder as they rotate. This can be seen in fallout with the exaggerated movement of the screwdriver (tension wrench) as the cylinder rotates. This can be accomplished with clever use of unity’s animation layers, and setting the appropriate time of the animation based on an internal representation of each object’s rotation. Here’s an example of the tension wrench using exaggerated movement as the cylinder rotates.

The game logic itself is based on the pick position, and several solution parameters that are generated based on difficulty. I don’t want to go too deep in detail in this post. The entire game logic can be found in the LockPickGame class.

The majority of the game can be fine-tuned by a designer using the exposed parameters in the unity editor. The game has a difficulty ranging 0 – 100, and the solution parameters are interpolated linearly based on the values provided in the editor. This included things like how quickly the pick breaks, how quickly it responds to player input, and how large the solution range is.

The lock pick game itself can be called from anywhere using the singleton class LockPickGameManager. This is not the only way the game could be used, but I wanted to include a method for invoking the game so I’ve included that manager in the project. The only scene in the project has a script that rotates the camera to a random location and opens the game at a random difficulty. Also, worth note is that the game models do not clip with anything in the scene. This is accomplished by rendering the current camera view to a texture, and then setting it as the background of the game, and moving the game to a remote location in the world.