Pushing Objects in Unity to Complete Puzzles

Going over how I implemented the player pushing another GameObject

Objective: Implementing a mechanic for the player to push a GameObject for puzzle completion purposes in my 2.5D game.


To get things started for today, I added a small cube to be pushed, as well as a smaller cube to act as our pressure pad. This can be seen in the screenshot below:

The Functionality

The overall goal in today’s article is being able to push an object onto a pressure pad to trigger an event. For now, that event will be to simply stop the cube when it is on the pad. As such, the first thing I did was implement the functionality for my cube to moved. I accomplished this with the following code here:

Notice how I grab the RigidBody component of the movable object. This is necessary to move the object. This gave me the result we have below.

With that, we can now check to see if the object made it to the pressure pad. To do this, I created the code we see below in a custom C# script I named PressurePad.

This gave me the following result:

That’s all for today’s article! Thanks for reading! In the next article, I will be going over some files available through GameDevHQ’s Filebase!




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Bagels Finance Testnet Farming Contest Closing Announcement

The Wonderful World Of Coding

AWS step functions: how to implement semaphores for state machines

Winamp To Spotify

How Industries Are Using Ansible

SQLite3 Database…

PolkaFoundry Weekly Community Update during 12-18 April 2021

Top 10 web developer interview questions you should know

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gabe Gomez

Gabe Gomez

More from Medium

Day 98: Character Animation Part 1

C# scripting in Unity — Day 01

Platformer: Player Animation Part 3

Bug Fix on Model Flip