# \[mx\] mouse angle detect

**URL:** <https://forum.kirupa.com/t/mx-mouse-angle-detect/23904>\
**Category:** flash\
**Created:** [June 24, 2003, 4:49am UTC](https://forum.kirupa.com/t/mx-mouse-angle-detect/23904 "2003-06-24T04:49:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonnooe](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jonnooe](https://forum.kirupa.com/u/jonnooe)\
**Post date:** [June 24, 2003, 4:49am UTC](https://forum.kirupa.com/t/mx-mouse-angle-detect/23904/1 "2003-06-24T04:49:50Z")

</div>

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

```auto

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

```

here is the range i want

```auto

  90
   |
   |
180-0
   |
   |
  270

```

and finally here is my code

```auto

_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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 24, 2003, 6:51am UTC](https://forum.kirupa.com/t/mx-mouse-angle-detect/23904/2 "2003-06-24T06:51:13Z")

</div>

ok… i think im getting what you want…  
try this.  
you should get angles like this o hope 😛 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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [June 24, 2003, 7:06am UTC](https://forum.kirupa.com/t/mx-mouse-angle-detect/23904/3 "2003-06-24T07:06:17Z")

</div>

i got it to work in the range i wanted it, but thx for the help anyways
