Hello soheil. I see two possible ways.
-
Writing your own compute.
-
Another way is to break the simulation into series of short runs and use if command (as you figured out already) to identify the contacting items.
I can elaborate on the second method if you would like.
Hope this helps.
Others might have better ideas.
Good luck
Arun