Rotate camera if player is about to go out of its view?

hmm… it worked in first time and after changing rotation of camera its not working… what would be the right way to do this?