Example 5.7 better collision detection