I've coded this function a long time ago (I remember it used to work) so maybe you can extract something out of it
REM ------------------------------------------------------------REM
REM Point Limb at object REM
REM REM
REM Proteus 1935 REM
REM ------------------------------------------------------------REM
REM switch names as you like...
REM Usage : pointturet(SourceObject,SourceLimb,Object to track)
function pointturret(Osource,Lsource,Otrack)
REM Deltas
DeltaY# =(object position Y(Otrack)- limb position Y(Osource,Lsource))
DeltaX# =(object position X(Otrack)- limb position X(Osource,Lsource))
DeltaZ# =(object position Z(Otrack)- limb position Z(Osource,Lsource))
REM distance between objects (2d)
distance# = sqrt(((deltaX#)*(deltaX#))+((deltaZ#)*(deltaZ#)))
REM Angles
Yangle# = wrapvalue(Atanfull(DeltaX#,DeltaZ#)+180)
angle# = wrapvalue(Atanfull(deltaY#,abs(distance#)))
set object rotation zyx Osource
REM Point
Rotate limb Osource,Lsource,angle#,Yangle#,0
endfunction
Currently coding: Massive collision system
Recent coding: An allegro game
Proteus