Unity Guide

Introduction to Physics in Unity

A quick guide about basic Physics in Unity

: Start implementing the physics system of Unity for a prototype of a space shooter game.

In Unity, we can enable the physics system through the component. It allows the gameobjects to have physics properties that can be detected in conjunction with the components, which will represent the interactive bodies of the gameobjects.

It’s important to recognize different types of collisions to decide which one can apply in our game:

Hard surface collisions

This type of collisions are the ones we see everyday in the real world. When we kick a ball, when a coin falls and bounces off the solid floor, when a boxer hits an opponent and knocks it out and every collision that applies forces between objects.

Trigger collisions

These are collisions we usually see in games where a player needs to collect items (coins, power-up, etc.) and when it touches them they disappear from the scene. This type of collisions doesn’t need a physics force feedback when they happen.

Start physics system implementation

Following the space shooter prototype from older posts, we need to have a enemy with behavior to attack from above, just like we did with the player and the laser behavior, so I’m going to suppose that we already have the enemy like this in the scene:

Unity physics system is not enabled yet.

As you can see above, the enemy and the player can pass through each other because the physics system is not enabled yet.

We need to do the following steps to enable it in the gameobjects that will collide (player, enemy, laser):

  • Enable the option in the collider components to identify trigger collisions inside the scripts.
  • Add a to the laser and the enemy. Then disable the option as we don’t want the gameobjects to fall in the scene.

Note: Do the first step for the playerand both steps for the enemyand the laser prefab.

If you leave the gravity on, the enemy will fall from the scene like this:

This way, we’ll be able to detect trigger collisions from the scripts by using one of the functions that is already built in Unity’s monobehaviour help methods, but that’s a topic that I’ll explain in the next post.

And that’s it, you can add physic properties to your gameobjects in Unity! :D. I’ll see you in the next post, where I’ll be showing how to use the right method to detect collisions in your game.

If you want to know more about me, feel free to connect with me on or visit my :D

--

--

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
Fernando Alcantara Santana

Fernando Alcantara Santana

A passionate computer technology engineer and Unity developer that is always looking to grow in every aspect of life :).