Member-only story

Physics in Unity

Valdarix Games
3 min readApr 9, 2021

--

Photo by Andrew George on Unsplash

Games aren’t very interesting if objects can’t interact with one another. Luckily Unity and MonoBehavior supply us with all the tools we need to bring our games to life. I mean what fun would a Space Shooter be if we couldn't blow stuff up.

Unity provides us with methods to handle 2D and 3D physics in our games. Since our prototype is working with cubes we will stick to the 3D versions in this article. Just note that a 2D version of these also exists.

For physics to work in Unity we need to make sure we have certain components on our relevant game objects. The first thing we need it a Collision Component, luckily for us the 3D objects we are using in the game already have colliders on them. Take a look at our Player object:

Our cubes have Box Colliders, Unity has several different types of colliders we can use and they can be added quickly by clicking “Add Component” and searching for colliders.

We can modify several things about the collider in this box. We can make it larger or smaller, move its location on the object, apply a material and set as a trigger. For our purposes we will set a trigger so that we can use Collison detections on objects that overlap.

The next thing we need to do is add a Rigidbody to at least one of the objects that will be involved in out collisions. We will add one to the Laser and…

--

--

Valdarix Games
Valdarix Games

Written by Valdarix Games

Turning my passion for video games and software development experience into a focus on video game development.

No responses yet