I just position the camera at the player x,y,z
point camera to object directection
move camera back
move camera up
point camera to object orientation.
maybe not the most efficient way to do it but it works without wrap angles

another way is this (i didn't write it but it should work) ..
function positionCameraToObject(obj,thirdPerson)
position camera object position x(obj),object position y(obj),object position z(obj)
rotate camera object angle x(obj),object angle y(obj),object angle z(obj)
if thirdPerson=1
pitch camera down 10
move camera -30
endif
endfunction