Legacy GM 3D Camera Auto Pitch


Hey, I'm wondering if anyone could point me in the right direction of solving this.

I'm currently developing a 3D game, and I'm wanting the camera to always be on the player. I have it rotating around the player object perfectly and there's no issue with it so long as the character and camera are at the same z. What I'm looking to do is add a way for the game to auto detect when the camera is not on the same plain as the player and angle itself toward the player by modifying it's pitch. The issue is that I'm not sure what kind of formula and commands I would need to implement this.

So far, I'm using this:

cam_dist = The distance from the player the camera is set to.
cam_pos = The direction in relation to the player's xy where the camera is positioned.
cam_height = The z value of the camera.

cam_x = x - lengthdir_x(cam_dist,cam_pos);
cam_y = y - lengthdir_y(cam_dist,cam_pos);
pitch = point_distance_3d(cam_x, cam_y, cam_height, x, y, z);

The issue with this is that the angle is way off. What I'm really looking for is a way to implement something like a point_direction for the z variable, but I have no idea how I would go about doing that. Point_distance_3d was the closest that I could find to that. Has anyone ever come across a problem like this? Any help would be greatly appreciated.