Ah yes doors are a love hate relationship in games
I remember I wrote code for opening a door "always away from player". Like, the player and the door knob are the two fingers of a watch, giving two angles with the door pivot via Atan2(). If the difference between them is higher than 180 degrees, add 360 to the lower number. Now turn the door CW or CCW, depending on which angle/number is lower. At least as far as I remember, and that's like 15 years ago ^^
I just dug this up:
[code]
// determine "away from player" opening direction factor (minus or plus 1)
dtmp=ccbGetSceneNodeProperty(currentNode, "Position");// pos door pivot
utmp=ccbGetSceneNodeProperty(ccbGetActiveCamera(), "Position"); // pos player
var rad_rel=57.29577951; // to convert atan2 output to 0-360 degrees
var adiv=Math.atan2(dtmp.x-utmp.x, utmp.z-dtmp.z)*rad_rel; // adiv#= ATan2((x1-ux),(y1-uy))
adiv=((adiv+180.0 + doorsa[door_i].y ) % 360.0)-180.0; //adiv#=((adiv#+180.0 +a) Mod 360.0)-180.0
if ((adiv >=-90) && (adiv <= 90)) { doorsdir[door_i]=-1; }
else { doorsdir[door_i]=1; }
[/code]
Notice: doorsa[door_i].y is the original angle of the door when closed.