Ontriggerenter2d



Ontriggerenter2d

An OnTriggerEnter2D example is shown. This example has two empty GameObjects, called GameObject1 and GameObject2. These both have script files which makes the example work. The first script, Example1, creates a Sprite and adds a BoxCollider2D and a Rigidbody2D. This object falls under gravity and collides with Example2. Use the Ambient Skies - Skies, Post FX, Lighting tool for your next project. Find this and more particle & effect tools on the Unity Asset Store.

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

Ontriggerenter2d vs oncollisionenter2d

Ontriggerenter2d Called Multiple Times

Ontriggerenter2d

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

Ontriggerenter2d

Void Ontriggerenter2d

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 Script writing software for mac free.





Comments are closed.