Sitemap

Creating a Pressure Pad using Interface.

4 min readJul 25, 2025

Objective: Creating a Pressure Pad using Interface.

Before starting to implement this feature, we will create a physics-based pressure pad. When an object is placed on the top of this pressure pad it will set the door state to unlock and allow the player to go to the door and open when interact with it.

Press enter or click to view image in full size

In the first step, select the top part, which is the pad, and add a spring joint to it.

Press enter or click to view image in full size

Select the base of the add a rigid body and set iskinematic is set to true. Then, disable the use gravity option, and of course, make sure it has a box collider.

Press enter or click to view image in full size

Select the Pad <Inspector < Spring Joint < Connected body and drag and drop the Base to the connected body.

Press enter or click to view image in full size

When the game starts, we want the pad to be unpressed. To do this, we want to reverse the Anchor and connected anchor of the base. So first, uncheck connected Anchor and set connected anchor to start at Anchor position(anchor of pad), and set pad anchor to the default position of connected anchor(To Connected Anchor, which is base).

Note: If I have confused you, please read about spring joints in the series of physics in Unity.

Here is the Link:

https://medium.com/@suleimanabdullah/spring-joint-101-5ff9c9b5c5d9

Press enter or click to view image in full size

Select the parent container for Pad and base, add a box collider, and edit it to allow the pad to touch it when it is pressed. Make sure the collider's isTrigger option is set to true.

Press enter or click to view image in full size

Important for this object to be able to reset the pad spring when the object is removed. I tried the spring value around 250 works well. Also, it's important that the box has a mass of 10 kg, so the value of the spring is going with the mass of the object 1 kg cant compress this spring at 250 value.

Create a script called Pressure Pad and attach it to Pressure Pad. Create a bool variable and an array of game objects. But if you only want one target, you can create one object.

Here we need to detect if the game object has a tag of Pad; we set the bool to true. Then we try to get the component of IInteractable of that target and call the activate method, which takes a bool variable.

Press enter or click to view image in full size

I have modified the IInterface signature, which allows Activate to take a bool variable and Unlock method to take a bool variable; then trigger isLocked to true if it was false before; setting isLocked to false if it was true before.
Note: I am sorry, I won't explain every detail here. This is the door script inherits the IInteractable Interface, and those pads are for a lock visual to tell the player if the door is locked or not by activating and deactivating the lock and unlock panel.

Press enter or click to view image in full size
Please read the first article about this door to grasp everything I try to explain here

Now, go back to the Pressure pad, create OnTriggerExist, and do the reverse of OnTrigger Enter.

Press enter or click to view image in full size

In the Last step, select the Pressure Pad <Inspector and drag and drop the Door C to the target. Make sure you set this door _isLocked bool to true when the game starts.

Press enter or click to view image in full size

Now I will position my player outside the door and position the box on top of the pressure pad.

Note: You may find that OnTriggerExit is called since the Pad may touch the collider, then the spring pushes it above, but when the box stops moving, the OnTriggerEnter is called again.

To solve this issue, increase the size of the collider of the Pressure pad.

Press enter or click to view image in full size

See you at the next one.

--

--

Suleiman Abdullah
Suleiman Abdullah

Written by Suleiman Abdullah

My name is Suleiman Abdullah. I learn game development and share what I learn by writing articles. :https://ko-fi.com/suleimanabdullah

No responses yet