Magnetic constraint

How does magnetic tool work?

I mean:

How does magnetic tool know that two entities had just touched?

I’m trying to make a tool that applies constraint.Weld when two entities touch (like magnetic tool works I believe) but I don’t know how to trigger that two entities touched together.

GOD, thank you.

EDIT: Isn’t what I wanted.

Wiki said:

This hook is not called right before two entities collide, but simply to poll if they should collide when they are about to touch each other.

I need to know when they are going to collide, not when they are near (what is happening).

[lua]function ENT:PhysicsCollide(data, phys)[/lua]

This function is not in the wiki.
It should be declared shared, as far as I know.

Look at Mad Cow’s Realistic CS:S weapons. You’ll be interested in the incendiary grenade.

But this is used to make a SENT, and I want to magnet two entities without the need of being scripted entities, like magnetic tool does.

The tool just replaces the selected entities, with phys_magnet entities.

Magnets have never worked for me. Didn’t know that they ever did for anyone else.

If two magnetised ents touch, they weld. Nothing else.