The below code is one example of retrieving information about collision events in a trigger:
var trigger = Entity.Get<PhysicsComponent>();
trigger.Collisions.CollectionChanged += (sender, args) =>
{
if (args.Action == NotifyCollectionChangedAction.Add)
{
//new collision
var collision = (Collision) args.Item;
//do something
}
else if (args.Action == NotifyCollectionChangedAction.Remove)
{
//old collision
var collision = (Collision)args.Item;
//do something
}
};
A collision object has two properties to help identify the objects involved in the collision:
ColliderA
ColliderB
I wondered when using the collision variable which is ColliderA and which is ColliderB? Is A the triggering entity or the trigger itself?
Here are the results:
Collision.ColliderA is the collider attached to the trigger.
Collision.ColliderB is the collider attached to the triggering entity (the entity that set off the trigger).
Hope that helps for those stuck trying to work out which is which.