Definition: By attaching the collider component, the game object can detect the collision with other game object in the game world. There are few types of collider such as BoxCollider2D, CircleCollider2D and etc. This collision detection mechanism can be implemented in 2 ways. This 2-ways of collision detection can be separated when “Is Trigger” is enable or disabled. We will go through with the details on our following discussion.
- Material: “Physics Material 2D” are the materials where you can adjust the “friction” & “bounce” of your following game object. For example, let us consider the fact that we want our game object to be a little bouncy when it collides with another game object. So to do that, we first created a “Physics Material 2D” from our “Project” Tab,
Now, to make it a little bouncy, let us change the value of “Bounciness” from “0” to “5”.
Finally, we will attach this “Physics Material 2D” to our “Material” section of our collider.
So now, when we collide with any game object, it will bounce to a specific direction based on the angle, velocity and force.
- Is Trigger: As we already said about the 2-ways of collision mechanism, here we are going to describe how these mechanism works.
-> Is Trigger (DISABLED): To understand the mechanism, let us see the following picture,
-> Here, both of the game object has collider where “Is Trigger” is disabled. When the “GameObject – 2” collided with the “GameObject – 1”, It has been redirect to the opposite direction. Here the redirection depends on the velocity, force and angle of the incoming object (“GameObject – 2”). But for the sake of the example, I just shown the opposite direction.
-> On the following example, we shown that the “GameObject – 1” didn’t moved from its place. It’s because either the game object doesn’t have the “Rigidbody2D” component (The Active Physics Component) or the mass of this game object is highly highly greater than the incoming game object.
-> Is Trigger (ENABLED):
As we now understand the basic concept of the collision when “Is Trigger” is disabled, it will now be much easier for us to understand the concept when the “Is Trigger” is enabled. To explain this concept, we will use the following image,
-> Here, the “GameObject – 2” is using the “CircleCollider2D” where “Is Trigger” is enabled. When the “GameObject – 2” has collided with the “GameObject – 1”, it didn’t redirect the incoming game object neither changed its position or rotation as the collider of the incoming game object has “Is Trigger” enabled. So now the question is, how this is going to help me on my development process?
-> Let us consider that you have a mine field in your game. If the player comes near to the mine field, it will blow. So now if we use this collider to the mine field, and start detecting if the minefield has collider with the player by using “OnTriggerEnter2D” Method, then we can simply write down the code for player death animation and where the user interface should be redirect after the death of player.
-> To get the different state of collision with “Is Trigger” enabled such as, enter, exit & staying collided, please check on the following hyperlink. OnTriggerEnter2D, OnTriggerExit2D, OnTriggerStay2D.
- Used By Effector: Right now, we will skip this section as we will describe with another post in more detail.
- Offset: It is basically the displacement of the collider on the different axis (X, Y, Z). Here, on the following screenshot, we made positive “1” displacement of the collider, where the game object is staying where it was, but the collider is shifted 1 unit along the positive X-Axis.
- Size: It denoted the size of the collider without changing the actual size of the game object itself. By default, the size of the collider is equal to the size of the game object (Here scale of the game object and size of the collider are not same. The same size mean where the size of the collider will be the size that required to give boundary of the following game object).
# The reference of the documents are taken from the “Unity – Documentation”.