Object Pushing Using Physics In Unity

Ben Pielstick
May 24, 2021

--

Physics is typically a tricky subject, especially when it comes to performance. So long as you’re only looking for something basic though, Unity makes getting started with physics easy.

Push the box until it’s on top of the button

In this example all we want to do is push a box around. Fortunately there are very few steps required for making this work.

First we need a box with a collider and a Rigidbody. We lock the rotation here so that the box slides rather than rolling
As long as our box is tagged, we can detect if we hit it when we bump into something, and then move it around by pushing it around in the same direction that we hit it from at the speed we were going.

That’s all there is to it, our player can now shove our box around as long as it remains kinematic. If we want the box to stop we can set isKinematic false, based on some other gameplay logic.

--

--

Ben Pielstick
Ben Pielstick

Written by Ben Pielstick

Game developer with over 12 years of experience, mainly focused on MMOs.

No responses yet