physics: rewrite collision detection and remove broken code