This pivot is called refraction. It happens because different materials have different densities. The more dense the material the more atoms the light collides with and the slower it travels; the less dense, the fewer the collisions and hence a faster velocity. This pivoting, or refraction, is caused by the light either slowing down or speeding up.