Lockpicking Mechanic from Fallout 4 recreated in Unity

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.


Standalone Demo Screenshot

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.


How It's Set Up:

I do not doubt that there are better ways of achieving this, but as this was mainly a project about further learning, I'll leave any refactoring up to you.

The lockpicking script is attached to the bobby pin gameobject, which is a child of the inner lock object. There is an additional bobbypin object that is used to animate, since the animator has control of the transform until Update() is completed. You could do this in LateUpdate(), but having a separate object to animate was how I chose to go about it.

Anyway, the script needs references to the lockpicking camera, the inner lock gameobject, the lockfollow empty gameobject (the pivot point of the bobbypin), the Animator attached to the lock gameobject, two Audio Sources, and some audio clips. The rest are simple variables, but I recommend leaving them where they are.

The camera is needed to find where the mouse is relative to the screenspace and the lockpick.

The inner lock is needed to be able to rotate the lock (and its children).

The lockfollow empty lets us set local position on the lockpick and keep track of where that point in space is when the lock is turned, since it is itself a child of the inner lock.

We have two audio sources so that one can be set to loop, and 7 audio clips, one for unlocking, one for the looping wiggle sound, one for breaking the pick, and 4 for when the bobby pin is being moved.

This script makes calls to the managers mainly for UI purposes, but also for handling lock difficulty.



Screenshots:

Models, Made in Blender

Models, Made in Blender

Lock Texture, Made in Substance Painter

Lock Texture, Made in Substance Painter

Screwdriver Texture, Made in Substance Painter

Screwdriver Texture, Made in Substance Painter

Bobby Pin Texture, Made in Substance Painter

Bobby Pin Texture, Made in Substance Painter





Credits:

You can find the project files on my github repository.


Code from FalloutLockPicking © 2024 by Evan Kurtz is licensed under GNU GPLv3.0https://www.gnu.org/graphics/gplv3-88x31.png

Assets from FalloutLockPicking © 2024 by Evan Kurtz is licensed under CC BY-SA 4.0

Download

Download
FalloutLockPicking_Standalone_Demo.unitypackage 111 MB
Download
FalloutLockPicking_Standalone_Demo-Win64.zip 43 MB
Download
FalloutLockPicking_Standalone_Demo-Mac.zip 52 MB
Download
FalloutLockPicking_Standalone_Demo-Linux.zip 41 MB

Install instructions

You can import the unitypackage or download the repository from my GitHub and load it from disk in the Unity Hub.

(The repository has all the scenes, including the ones I used during development.  The unitypackage just has all the necessary stuff for the build proper.)

Development log

Comments

Log in with itch.io to leave a comment.

This is great. Absolutely love the fully fleshed out mechanic. Nice job

(+1)

Wow thanks! That means a lot coming from you! Thanks for the tutorial! It really helped me wrap my head around how this mechanic worked