Introduction to Physics in Unity

Ameen Mohmand
3 min readJun 18, 2022

Objective: How do Physics work in Unity.

Today were gonna focus on our laser colliding with the enemy and being destroyed. I will break down the process now since we already establish the behavior for our laser. In addition were gonna see how the enemy damages the player when it collides. If you notice our Player and Enemy including our Laser have colliders. Colliders are what detect collisions in our games physical world.

In addition if you notice our player and enemy aren’t detecting each other because we haven’t enable the physic system of Unity. In Unity we use physics through a Rigidbody which adds physics properties to an object. Colliders are not enough to handle collision in our Space Shooter Pro.

In Unity there are two types of collision Hard surface collisions and Triggers Collisions. One example of a Hard surface collisions is when you throw a ball against a concrete wall and the ball bounces back to you. The next type is Triggers Collisions which is like an illusion your collecting the item but your just passing through the object but your not acting on the object. The way you do that is in your Box Collider there is a check box called Is Trigger. So initially you want to check that so objects can pass through like our laser, so appears as if was destroy. Now we want our Enemy and Laser to be Triggers so when the Laser pass through the Enemy it doesn’t bounce off. Also we need the Player to be a Trigger as well so it pass through the Enemy it appears as if you died. This gives an appearance as if it was collected or destroyed. So in other words we don’t want surface collisions we want pass through collisions. There are two type of Collisions Hard Collisions and Pass through Collisions there are methods that help you in Unity. Those methods are called OnTrigger Collisions which are pass through Collisions and OnCollisions which are hard surface collisions. Which of the two we will be using you asked , it is OnTrigger. The three types of OnTrigger are OnTriggerEnter, OnTriggerExit , OnTriggerStay. OnTrigger is when GameObject collides with another GameObject. Both GameObjects must contain a Collider component. One must have Collider.isTrigger enabled, and contain a Rigidbody. If both GameObjects have Collider.isTrigger enabled, no collision happens. The same applies when both GameObjects do not have a Rigidbody component. So this case lets give our Laser and Enemy the Rigidbody. This in a nut shell is a introduction to physics in unity.

--

--