Pushing Objects in Unity to Complete Puzzles

Andrea Alicino
2 min readJun 29, 2021

--

One of the most common actions in 2D and 2.5D games is to move objects to solve puzzles.

The day's objective is just that, to move a cube, push it with our player, and activate a button on the floor.

First, we must make sure that the cube recognizes the collision with our player. To do this we use a method of Unity very similar to the classic “OnTriggerEnter” but more specifically to recognize only collisions.

Now we just have to take its Rigidbody and apply the push of our player through its velocity.

Very important, the cube we want to move must have a Rigidbody.

To avoid that the cube rolls instead of being pushed it is better to set the constraints always on the Rigidbody blocking the rotation on all axes.

To create a button that recognizes the pressure of our cube we will use the OnTriggerEnter function.
I recommend that in order for this to work, you must construct the tag to be assigned to the cube or in general to the objects you need to move, otherwise nothing will work.

This is the final result.

--

--

Andrea Alicino
Andrea Alicino

Written by Andrea Alicino

Game Developer Unreal Engine/Unity. Computer science graduate. Seeking new opportunities.

No responses yet