Problem with collisions in Top Down Shooter game?

Hello Everyone!

So I’m currently learning the Unity Game Engine by doing the Unity Pathways courses, it’s been a very fun process and I’m really enjoying applying all of the previous programming knowledge I’ve had in the Game Dev context. I’m currently working on my Personal Project assigned in the Junior Programmer course. I’ve decided to try and create a simple wave based 3d top down shooter, I thought this was a simple idea but it turned out to be a bit more complex than what I thought, especially in the collision department.

So I’ve currently got the Basic Gameplay down, the player can move in all directions, shoot projectiles and i’ve also added a neat little Dash mechanic to it. I’ve also added a couple of enemies that can also shoot projectiles at the player and follow him. The main problem I’m having now is that I’m using Trigger Colliders to run the code I want for the interactions between playerprojectile/enemy and vice-versa, this then makes it so the player gameobject won’t collide with the enemy gameobject’s and they’ll phase through eachother and i’ve been trying to find a way to make it so this won’t happen. After some research I think I’ll have to use the Unity Layers System to fix this but I’ve been having a hard time understanding how it works and how to apply it to my project.

Hope somebody can help and thanks in advance :slight_smile:

I also don’t enjoy using layers or triggers and so you don’t need to use them at all. But you do need to be careful when spawning rigidbodies and to make sure they don’t overlap other objects or they could interfere with their trajectories.

The biggest benefit of layers is that they help to improve performance because it means the physics engine only has to check for collisions of objects that share the same layer. So player bullets only need to check against enemies etc.

But for now if you’re struggling to understand layers then you could just ignore them until you become more comfortable using Unity.

Ok I see. So is there any other simpler way of making it so my player gameobject and enemy gameobject won’t just pass trough eachother?

Yes, don’t make them triggers and if necessary use OnCollisionEnter or OnCollisionEnter2D to get a collision callback from within an attached script. And remove colliders from any background objects like the ground that don’t need to be interacted with. Triggers may be okay for projectiles.