# Mouse Following Actionscript ?'s

**URL:** <https://forum.kirupa.com/t/mouse-following-actionscript-s/23917>\
**Category:** flash\
**Created:** [June 24, 2003, 8:02am UTC](https://forum.kirupa.com/t/mouse-following-actionscript-s/23917 "2003-06-24T08:02:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![posix](https://avatars.discourse-cdn.com/v4/letter/p/5f9b8f/32.png) [@posix](https://forum.kirupa.com/u/posix)\
**Post date:** [June 24, 2003, 8:02am UTC](https://forum.kirupa.com/t/mouse-following-actionscript-s/23917/1 "2003-06-24T08:02:51Z")

</div>

Hi,

I got a script running that rotates an image depending on where the mouse is in the movie…

[AS]  
a = sun.\_y-\_ymouse;  
b = sun.\_x-\_xmouse;  
angleA = Math.atan2(a, b);  
degrees = angleA/(Math.pi/180);  
setProperty (“sun”, \_rotation, degrees);  
[/AS]

I want this movement to ease… maybe using the speed= command? But cant figure out how to do it… I also would like the image to rotate at a slow pace on its own even if the mouse isnt in the movie to follow.

I can post the .fla if you need it.  
Thanks a bunch!

---

<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, 8:40am UTC](https://forum.kirupa.com/t/mouse-following-actionscript-s/23917/2 "2003-06-24T08:40:11Z")

</div>

i think that give the movie clip an instance name and link the action with the instance. that’s how other mouse follower’s work !

---

<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, 10:34am UTC](https://forum.kirupa.com/t/mouse-following-actionscript-s/23917/3 "2003-06-24T10:34:39Z")

</div>

umm… i dont understand.

---

<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, 4:38pm UTC](https://forum.kirupa.com/t/mouse-following-actionscript-s/23917/4 "2003-06-24T16:38:29Z")

</div>

[AS]  
a = sun.\_y-\_ymouse;  
b = sun.\_x-\_xmouse;  
angleA = Math.atan2(a, b);  
degrees = angleA/(Math.pi/180);  
sun.\_rotation = degrees;  
sun.\_x += (\_root.\_xmouse-sun.\_x)/5;  
sun.\_y += (\_root.\_ymouse-sun.\_y)/5;  
[/AS]

Try that. And setProperty is old, use the new dot syntax 😉 (example in my code)

sun.\_x += (\_root.\_xmouse-sun.\_x)/5;  
sun.\_y += (\_root.\_ymouse-sun.\_y)/5;

These lines to be run onEnterFrame btw. \_xmouse and \_ymouse are the final positions of the clip, you subtract the current \_x or \_y position to get the different and 5 is the speed it travels (the higher the number the slower the speed) because it gradually divides by the position which makes it ease.

Heres a tutorial on mouse following with easing…

[http://www.kirupa.com/developer/mx/followease.htm](http://www.kirupa.com/developer/mx/followease.htm)

---

<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, 5:10pm UTC](https://forum.kirupa.com/t/mouse-following-actionscript-s/23917/5 "2003-06-24T17:10:42Z")

</div>

Lostinbeta…  
Thanks for the code…  
I tried what you suggested, but it did not make the desired effect. Instead of the rotation being eased, the whole MC follows around my cursor.

Maybe you could look at it for me if you have some time…  
Thanks, I appreciate it!

---

<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:05pm UTC](https://forum.kirupa.com/t/mouse-following-actionscript-s/23917/6 "2003-06-24T19:05:48Z")

</div>

[AS]a = sun.\_y-\_ymouse;  
b = sun.\_x-\_xmouse;  
angleA = Math.atan2(a, b);  
degrees = angleA/(Math.pi/180);  
var diffAngle = degrees - sun.\_rotation ;  
sun.\_rotation += diffAngle/5 ;[/AS]pom :phil:

---

<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:14pm UTC](https://forum.kirupa.com/t/mouse-following-actionscript-s/23917/7 "2003-06-24T19:14:59Z")

</div>

Wow i’m stupid, I misread the question 😛

---

<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, 8:10pm UTC](https://forum.kirupa.com/t/mouse-following-actionscript-s/23917/8 "2003-06-24T20:10:27Z")

</div>

hey yeah this is cool

---

<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 25, 2003, 3:24am UTC](https://forum.kirupa.com/t/mouse-following-actionscript-s/23917/9 "2003-06-25T03:24:51Z")

</div>

ahh, thanks pom!

just what i was looking for.

Thank you all for helping me out

---

<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 25, 2003, 4:00am UTC](https://forum.kirupa.com/t/mouse-following-actionscript-s/23917/10 "2003-06-25T04:00:04Z")

</div>

hmm… i spoke too soon. heh

Ok, it looks good and it does what its suppose to except when it gets to a certain point in the rotation. For me, the right side of the image, the sun will stop following the mouse and then spin all the way around in the opposit direction to catch up with it on the other side.  
Sounds kinda confusing so I attached the fla…  
Is there any way to defeat this?

Thanks
