Time for action – adding collisions
We need to add some collision capabilities to our space objects, so that they can crash into each other and be shot at properly:
Let's start by giving collision to the asteroid. Do this by first selecting the mesh for the asteroid and adding a MeshCollider component. This will later let us shoot at the asteroid.
Next, select the same object that holds our
Asteroid
script component. Add a SphereCollider component to the object and adjust the Radius to be a little larger than the asteroid. This collider will detect when the asteroid has collided with the player.The SphereCollider needs to have the Is Trigger checkbox checked. We are not checking the true collision, just an approximate one. With this checkbox checked, objects will no longer be stopped by the collider, but instead trigger an event in script when an object enters the collider volume. When the player enters the collider, it will be close enough that we can assume and act as if it has collided...