Making a magnet

what kind of math would I have to do? and why avoid using event tick?