Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-11-2012, 07:17 PM   #1
Registered User
Join Date: Feb 2012
Location: Warsaw, Poland
Posts: 28
Default Rotate in the direction of the mouse

I am horrible at maths and I would like to ask how to make an object ex. an arrow turn into direction of the mouse? I know that there would be helpful Event.ENTER_FRAME and some mathematical functions, but I cant tell which and how to use them.

hydr4nt is offline  
Old 02-12-2012, 02:39 AM   #2
Registered User
Join Date: May 2011
Posts: 33

There is a bunch of tutorials for this, but I didnt want to find one, here would be the code to make the MovieClip you want follow the mouse cursor:

ActionScript Code:
addEventListener(Event.ENTER_FRAME, everyframe); function everyframe(e:Event):void{     var differenceX = mouseX - movieClip.x;     var differenceY = mouseY - movieClip.y;     var radianToDegrees = (Math.PI/180);     main.rotation = Math.atan2(differenceY, differenceX)/radianToDegrees; }

tell me if u want me to explain it.
backshesh is offline  
Old 02-12-2012, 07:37 AM   #3
Registered User
Join Date: Feb 2012
Location: Warsaw, Poland
Posts: 28

For me it works correctly. Thanks backshesh
hydr4nt is offline  
Closed Thread

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 02:00 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.