Ontriggerenter2d



Unity on trigger enter

  1. Ontriggerenter2d Vs Oncollisionenter2d
  2. Ontriggerenter2d Not Working

Script error: OnTriggerEnter2D This message parameter has to be of type: Collider2D. I have a BoxCollider on an empty object that is a child of my player. When it collides nothing happens. I've set IsTrigger to true. Player's child script. DestroySelfAndKillOtherOnCollision.cs - using UnityEngine using System.Collections public class MonoBehaviour public void OnTriggerEnter2D(Collider2D.

Ontriggerenter2d

To reproduce:
1. Create two 2D cubes with colliders 2d
2. Attach a rigidbody 2D to one of the cubes and make the other cube a trigger
3. Attach a script with OnTiggerEnter2D (and some kind of debug message) to the rigidbody cube
4. Enter play mode and move the cube into the other cube - the debug message should get printed
5. Change the rigidbody 2d to kinematic - the debug message is no longer printed, OnTriggerEnter2d is no longer being called

Explanation: kinematic bodies (specifically colliders attached to those bodies) only collide with dynamic bodies.

Ontriggerenter2d Vs Oncollisionenter2d

  1. A Rigidbody2D just tells a GameObject how to interact with the physics engine. It doesn't provide a collider for collision. From the Unity docs for RigidBody2D By adding the appropriate collider component, the sprite will also respond to collisions with other sprites.
  2. DestroyOnCollision.cs - using UnityEngine using System.Collections public class DestroyOnCollision MonoBehaviour public void OnTriggerEnter2D(Collider2D.
  3. Debug.Log isn't working because the OnTriggerEnter2d function is never being called because that object does not have a trigger component attached. Either put a trigger collider on the bullet, or change it so the logic is on the enemy shit instead of the bullet. It would be better, in my opinion, to do the latter.

Ontriggerenter2d Not Working

The allowed collisions for body types are therefore:
Kinematic can collide with Dynamic
Dynamic can collide with Static, Dynamic & Kinematic
Static can collide with Dynamic