How to Ignore a Collider on a GameObject

Jordan Evans
Nov 1, 2021 · 3 min read

Let’s take a look at how we can implement a blood splatter system now to our shooter. To start, we just need to find a good splatter to work with and attach a prefab of it as a gameobject for our shoot script:

In order for our splatter to not just spawn at the same rotation value all the time, whether we shoot it head on or from the side, we need to apply the lookrotation logic to the instantiation method so that it will rotate around our object nicely:

Now that we have a nice splatter that will change it’s rotation depending on where we hit the object, we can see a slight issue at hand. As noticed above, we are currently hitting an invisible sphere around our enemy. This is because our shots are being stopped by the attack state collider we applied to the enemy earlier when we were dealing with implementing various attack states. In order to fix this, we are going to have to make a couple adjustments to our scripts, as we will want to make this collider a child object of the enemy. To start, we are going to take the logic of the state changing over to a new script, and make a couple small adjustments to it:

There changes are just calling upon specific voids that we will have to set up in our enemy script that will change the state of the enemy to the one we desire:

Now that we have this part in place, and have tested it in game to be sure that the enemy has the same type of behaviour, let’s take a look at how we are now able to ignore the state collider and hit just the enemy:

With this adjustment in our game code for the raycast, we are telling Unity that we want to have everything on layer 0 to be hit. If we decided to add additional layers that we want targeted, we would simply add “| 1 << x” next to our last part of the code on that line. Now that we have this in place, let’s see how it looks within the game:

Now that we have a working splatter system, we can start on our next part of the game.

Nerd For Tech

From Confusion to Clarification

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Jordan Evans

Written by

Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.