Hi,
I’m creating a simple 2D ‘game’. I am having problems with layerbased collisions. Player’s bullets with a Rigidbody2D collide with the player who fires them so they immediately get destroyed.
I have a Bullet component attached to them which implements this method.
The bullets have a kinematic Rigidbody2D and isTrigger enabled.
I have also tried the OnCollisionEnter2D method and setting the Rigidbody2D to dynamic and disabling isTrigger, but in this case, the same happened.
The collision matrix looks like this.
There are also enemy gameObjects which are supposed to fire bullets of layer EnemyBullets but they they get immediately destroyed as well.
I am sure I have set the layers of the game objects correctly.
Also, could somebody explain me the difference between OnCollisionEnter(2D) and OnTriggerEnter(2D) and what the isTrigger is. I’ve read about it in the docs a few times but didn’t really understand.
There are huge numbers of tutorials online to watch about this subject so I’d look at one of those. You get trigger callbacks when either of the colliders that come into contact with each other is a trigger and you get collision callbacks when that’s not the case.
The most obvious thing wrong above is that you’re configuring the 3D physics settings and not the 2D physics settings. Go back to Unity and look at the Project Settings and you’ll see “Physics” and “Physics 2D” next to each other.