Puzzles Pt4

Chris Didier
3 min readApr 21, 2021

--

Sometimes to get past certain objects you have to just push right on through them. Well that is what I will be talking about how to do today. How to push through a box in part 4 of our puzzle building level. The challenge here is there is a box that we need to push onto a pressure pad. When the box is on the pressure pad it will turn green.

So the box will know that we are coming into contact with it the same way the wall knew we had come into contact with it by using ControllerColliderHit. Now for this situation that will be expanded upon as we do not want to push the object beneath or above us but only along the x direction using a force created by the player.

So if we hit the box with our player we tell the box that we are going to push it in the x direction. How fast we push it is determined by our push power. We must also tag our box with the “Box” tag.

We must also set the rigidbody component on the box to freeze rotation, because when the player hits the box it will not slide, but roll which we do not want.

We will now need to create a pressure pad script and attach it to the pressure pad. When pushing the box it goes till it is on top of the pressure pad. When it is over the pad the pad will recognize the box has entered it’s space and will change color from yellow to blue. To do that we will be using OnTriggerStay. We will need to measure the distance between the box and the pressure pad. To do this we will be using Vector3.Distance( ). Once we have gotten the distance between the box and the pressure pad must also get the rigidbody of the box and the Mesh Renderer from the child of the pressure pad and if the box is within a set range change the color of the pressure pad to blue and box is kinematic at this point.

and with that our puzzle series is now complete and we will be moving forward into the next section of our game creation.

--

--

Chris Didier
Chris Didier

No responses yet