camera.x = me.x + fcos(my.pan,-1 * distance);
camera.y = me.y + fsin(my.pan,-1 * distance);
vec_diff(temp.x,me.x,camera.x);
vec_to_angle(camera.pan,temp.x);
I found that in one of the tutorials on the wiki. Works for me. I too have to resolve the camera going into walls which I believe was also addressed in those tutorials but I haven't looked into that portion yet.
Wiki Tutorials