PDA

View Full Version : [mx] mouse angle detect



jonnooe
June 24th, 2003, 12:49 AM
ok so i have been trying to detect the mouse angle.. kinda figuring it out on my own to learn new stuff and get a better understanding of actionscript, but ive kinda run into a problem i cant figure out.

here is the range of angles i get


0
|
|
90-----90
|
|
0


here is the range i want


90
|
|
180-0
|
|
270


and finally here is my code


_root.onLoad = function(){
var a, b;
var convert;
var ang;
}

_root.onEnterFrame = function(){
xCoord = (_xmouse - 200);
yCoord = (_ymouse - 200)*-1;
calcAngle();

}

_root.calcAngle = function(){
a = Math.abs(xCoord);
b = Math.abs(yCoord);
ang = Math.atan(a/b);
convert = 180/Math.PI;
mouseAngle = ang*convert;
}


any help would be greatly appreciated, thank you

whet15
June 24th, 2003, 02:51 AM
ok.... i think im getting what you want...
try this.
you should get angles like this o hope :P i never had time to test it but iv done some work on this sort of thing before

270
^
|
|
180<------->0
|
|
\/
90

_root.calcAngle = function(){
a = Math.abs(xCoord);
b = Math.abs(yCoord);
convert = 180/Math.PI;
mouseAng = Math.atan(b/a)*convert;
}

that should work but im not sure :S

jonnooe
June 24th, 2003, 03:06 AM
i got it to work in the range i wanted it, but thx for the help anyways