Need help with camera roration

Good day community!

I got a script that controls a camera.

This works perfect over a flat surface if the camera is fixed to world’s z axis. But as you can see in the blend file below the cube moves over a spherical surface, so the camera does not works properly because I set the position in world coordinates, and it should be in local. I have been stuck here for weeks and still can’t solve it (I have solved it in Unity3D using Quaternions, but the point here is to not use Unity3D)