# Problems with angles

**URL:** https://forum.kirupa.com/t/problems-with-angles/65329
**Category:** Uncategorized
**Created:** [September 25, 2004, 1:56am UTC](https://forum.kirupa.com/t/problems-with-angles/65329 "2004-09-25T01:56:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Scooterman](https://avatars.discourse-cdn.com/v4/letter/s/8dc957/32.png) [@Scooterman](https://forum.kirupa.com/u/Scooterman)
#### Post date: [September 25, 2004, 1:56am UTC](https://forum.kirupa.com/t/problems-with-angles/65329/1 "2004-09-25T01:56:00Z")

</div>

Hi, I am trying to make a small movieclip that rotate itself based on the mouse coordinates while pressed. But the problem is, using the Math.sin function, when I pass the result to angle it won´t go to far than 50 degrees where it should be 90. What´s the matter?  
My code

on(press){  
isActing = True;  
}

onClipEvent(enterFrame){

if (isActing == True){  
//This is to get the real coordinates based on the movieclip position  
tx = \_root.\_xmouse - this.\_x;  
ty = - (\_root.ymouse - this.\_y); // y is inverted in flash

```
hyp = Math.sqrt(tx*tx + ty*ty);

sin = Math.sin(ty/hyp);
angle = 180 * sin / Math.PI;

```

}  
}

I was planing to get a base angle and the current mouse angle and then subtract they by rotating the movieclip. But so I´ve got the angle problem. How do I fix it??

Thx, Scooterman

---

<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: [September 25, 2004, 4:11am UTC](https://forum.kirupa.com/t/problems-with-angles/65329/2 "2004-09-25T04:11:49Z")

</div>

you should use atan2

\_rotation = Math.atan2(ty, tx)\*180/Math.PI

---

<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: [September 25, 2004, 6:56pm UTC](https://forum.kirupa.com/t/problems-with-angles/65329/3 "2004-09-25T18:56:14Z")

</div>

Tkz Senocular, but this function has a problem: if i start to press on the top of my movieclip it will follow the mouse to de rigth and left very wel. But, if press in the same place and move the mouse in a circle going down, after passing the center of the image the rotation invert and start to move in the opposite way, insted of keep moving. How I can handle this problem???

Scooterman

---

<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: [September 25, 2004, 7:30pm UTC](https://forum.kirupa.com/t/problems-with-angles/65329/4 "2004-09-25T19:30:03Z")

</div>

If I understand what you’re saying, you just need to include an offset. When you click the movieclip, find the angle to the mouse at that point of time and base all further movement off that angle. In other words, add it to the equation above.
