1
votes

I am starting with Unity 5 and I am straggling a bit with its 2D collisions. Looking a bit into it I found that there are three types of objects that can be defined: - Static: Just a 2D collider (2D collision box component for example). - Dynamic: 2D collider + 2D rigid body. - Kinematic: 2D collider + 2D rigid body set to kinematic.

And as far as I know they collide this way: Static: Only collides with dynamics. Dynamic: Only collides with statics and kinematics. Kinematic: Only collides with dynamics.

I am trying to make a simple Space Invaders and I am struggling to define the collision types of the different elements (aliens, player, alien bullets and player bullets). I imagine I can set objects to dynamic and disable the gravity to match the correct collision types.

But my question is, for example I want to make a simple game with a few enemies of the same type (instantiating a prefab), and I want those enemies to detect collision with each other. How I am supposed to setup the enemy collision properties to achieve that?

Many thanks in advance!

1

1 Answers

0
votes

Personally I would set the enemies in the same layer with each other, and make sure they are colliding with each other. You can set the layer of the prefab in the inspector, where it is located underneath the name, as you can see here:

enter image description here

Once you click on the layer, there is an option to add new layers as well, at the complete bottom.

Then I would set the Layer Collision Matrix through menu Edit - Project Settings - Physics 2D to match the layers that need or need not to collide with each other, like so:

enter image description here

In this example the Enemy layer won't collide with any other layer than itself.