Here’s just an example interaction of what to do when you push the movable box to a pressure pad:
- Stop the box from moving when it’s around the center of the pressure pad
- Change color of pressure plate to blue
Of course in games, you would want this interaction to open doors or unveil secret walls or bridges but it’s important to address the basics.
We will add a new code to the Pressure Pad:
It’s not enough to check when the box just touches the pressure pad. We have to check which part. This is why we need to determine this via distance:
If the distance is enough, we will remove kinematic from the box which means the Physics aspect of the box can only be simulated by code alone. We also, change the pressure pad to blue to show the new behavior. For optimization, we need to stop listening to the collision between the Pressure Pad and Moving box by deleting the PressurePad component.
Now, we are able to customize behavior between moving box and pressure pad.