Unity/C# Challenge 54: Push the Box.

Alec Oney
Dec 6, 2021

Challenge: Implement a Box Puzzle in our game.

Currently, we have enacted our collectables system, our elevator, and our wall jump. The last hurdle we have to clear is our box puzzle:

We want to be able to push the box onto the yellow pad. To do this we modify the OnControllerColliderHit method within our player script by adding this:

Where _pushpower = 2 in the global variables

to our code. In this case, when the player hits the box, we grab the rigidbody of the box, and move it by the direction and push modifier of the player. This then allows us to move the box:

in order to prevent the box from “rolling”, simply freeze rotation in the box’s rigidbody:

--

--