Creating a Pressure Pad
Adding more depth for your pushable objects
Now that we have created pushable objects, it is time to add another use for them and that is “Pressure Pads”. Pressure pads, as the name already describes is a collision element that checks for moving objects, and when the moving object (ie. Player or moving box) stays in the trigged area for a set duration, it would trigger another sequence (ie. a door opens, or a passage unlocks etc.)
Setting Up the Pressure Pad:
Setting up the pressure pad is rather easy, as long as you create an 3D object that has a type of collider that is set as Trigger.
We are going to create a new C# script for the pressure pad. Since the pressure pad is just going to be an Trigger object, it just needs to check for any collision. Since we already have a tag which all pushable objects are under, we can have the Trigger event check for that.
We also want the pushable box to overlap the pressure pad by a certain set distance before the pressure pad can work. Therefore we need to have an distance variable to calculate the distance of two objects. In this case it will be the pushable box and the pressure pad.
Create a float variable called “Distance” which we are going to check the position of current object (which is the pressure Pad) and also the object stored within the other variable (which is going to the pushable box.)
In another If statement we set the distance constrains to be under 0.05f which then triggers the set conditions. In this scenario, I want two things to happen when the box collides with the pressure pad. 1) I want the pushable box to become Kinematic (which becomes non-interactive). 2) I want the pushable box to change color to allow the player know that the box has triggered the pressure pad properly.
Once that is done, the end result should look like this: