Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

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 ^^ 

(+1)

Thats actually very helpful im gonna try and replicate that somehow

(2 edits)

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.

Youre a lifesaver! 

Glad to help. Just added this to a current project, but (again) forgot that JS atan2 does not use -180 to 180 degrees, but I guess something like 0 to (Pi/2)- so I tried to find the "bug" for quite a while lol.