Implement collision detection.