This page describes how to filter and detect objects collisions.
Flax supports up to 32 different collision layers. Each layer can have different collisions mask defined globally. You can use Physics Settings to define the layers collisions mask matrix. Every actor has property Actor.Layer which is used to peek the collisions mask for the object.
Flax uses event-based collisions detection. When the content between two objects is detected it gets reported during the fixed update. Use the Collider events to handle the collisions. To access information about the collision use Collision class and ContactPoint structures.
Here is an example script that registers for the collision detection for the given input collider in your scene.
public class MyScript : Script
{
public Collider TargetCollider;
public override void OnEnable()
{
TargetCollider.CollisionEnter += OnCollisionEnter;
}
public override void OnDisable()
{
TargetCollider.CollisionEnter -= OnCollisionEnter;
}
private void OnCollisionEnter(Collision collision)
{
Debug.Log("We got the collision sir! With: " + collision.OtherCollider);
}
}
Please keep in mind that not only Colliders may be a source of collision but also other actor types eg. Terrain. To handle this use properties ThisActor and OtherActor.
See Script Events page to learn more about the C# script events.