How do I conditionally collide two objects depending on a variable in 2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By dragon

If I have objects for example gunmen and cover, such that a gunman can collide with cover, normally for example I would give the gunmen collision layer of 1 and a mask layer of 2, while I would give the cover a collision layer of 2 and a mask layer of 1.

The problem is that I am simulating height in this 2D world by making a variable called elevation. If for example I have a gunman and his elevation is different to that of a tree, then I don’t want them to collide, how would I achieve this?