Help ! Zigzag ray.

I want to set a path for bullet like this img. .

Please help me with the code !
And how can i detect the surface (left / right side is vertical , top / bottom is horizon) ? Thanks !

Hope it helps

Thanks! you save my time !