at the moment it is not working at top left correct(about 10˚ of rotation at about 180˚ off) and bottom left is inverted (180˚ to much). I had all but top left working but when fixing that I broke the bottom left.
It should make a top view of a man rotate to face the mouse. 0 rotation of the man he is facing down, this was unintentional the code was intended to make him face up but I didn’t mind
This code is for a RPG that I am making for a beginner’s flash class
http://www.ping.be/~ping1339/gonio.htm (I added this link coz this is the referents I used to refresh my understanding of Trigonometry. Might be useful for some keen people)
onClipEvent (load){
Cx = Stage.width/2
Cy = (Stage.height/2)- 30 //the 30 is to les on the inpact of the interface
}
on (release){
//rotashon of man
if (_xmouse >Cx && _ymouse>=Cy){ //betwen 0 and 89 top right θ./_|
Radian= ((Math.PI/2) - Math.atan( (_ymouse-Cy)/(_xmouse-Cx) ))
}
if (_xmouse >=Cx && _ymouse<Cy){//betwen 90 and 179 botom right θ`|_\
Radian=(Math.PI/2) +((Math.PI/2) - (Math.atan((_xmouse-Cx)/(Cy-_ymouse))))
}
if (_xmouse <Cx && _ymouse<=Cy){//betwen 180 and 269 botom left /_|`θ
Radian=(Math.PI/2) + (Math.atan((_xmouse+Cx)/(Cy-_ymouse)))
}
if (_xmouse <= Cx && _ymouse > Cy){//betwen 270 and 359 top left |_\.θ
//Radian=((2*Math.PI) + ((Math.atan((_ymouse-Cy)/(Cx-_xmouse)))))
Radian=((2*Math.PI)+(Math.PI/2) + ((Math.atan((_ymouse-Cy)/(Cx-_xmouse)))))
}
_global.man_angal= Radian*(360/(2*Math.PI)) //convert Radians to Degree
trace("Radian "+Radian)
trace("man_angal in deges "+_global.man_angal)
//send moveing instrucshons
if (((Cx + 10)> _xmouse)||(Cx - 10)< _xmouse) {//test for minamin movement
_global.moveX = (_xmouse-Cx)//send moveing instrucshons
}
if (((Cy + 10)> _ymouse) || (Cy - 10)< _ymouse) {//test for minamin movement
_global.moveY = (_ymouse-Cy)
}
}