Detecting collisions
As you can see, proper physics settings can be complicated and very important, but now that we have tackled that, let’s do something with those settings by reacting to the contact in different ways and creating a health system in the process.
In this section, we will examine the following collision concepts:
- Detecting Trigger events
- Modifying the other object
First, we are going to explore the different collision and trigger events Unity offers to react to contact between two objects through the Unity collision events. This allows us to execute any reaction code we want to place, but we are going to explore how to modify the contacted object components using the GetComponent
function.
Detecting Trigger events
If objects are properly configured, as previously discussed, we can get two reactions: collisions or triggers. The Collision reaction has a default effect that blocks the movement of the objects, but we can add...