Home Tutorials Forums Articles Blogs Movies Library Employment Press

 ActionScript.org Forums [AS3] Make Turrent with Transfrom.matrix
 Register FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

 07-19-2012, 08:57 AM #1 GiaTuan Registered User   Join Date: Sep 2011 Location: HoChiMinh city,Vietnam Posts: 44 [AS3] Make Turrent with Transfrom.matrix I have a movieclip named Gun.Movieclips registration is top left corner. I found script to rotate movieclip at its center: ActionScript Code: ```function rotateAroundCenter(ob, angleDegrees) {     var m:Matrix=ob.transform.matrix;     m.tx -= point.x;     m.ty -= point.y;     m.rotate(angleDegrees*(Math.PI/180));     m.tx += point.x;     m.ty += point.y;     ob.transform.matrix=m; }``` Gun will shoot the mouse.How to use this script to rotate Gun when the mouse is moving? Last edited by GiaTuan; 07-19-2012 at 09:00 AM.
 07-19-2012, 03:28 PM #2 -:)lauri Senior Member   Join Date: Aug 2008 Location: Helsinki, Finland Posts: 1,184 To put the gun to rotate related to mouse ActionScript Code: `gun.rotation = Math.atan2(mouseY - gun.y, mouseX - gun.x) * 180 / Math.PI;` and to put the gun to point to the mouse ActionScript Code: `gun.rotation =  offsetDir + Math.atan2(mouseY - gun.y, mouseX - gun.x) * 180 / Math.PI;` where the offsetDir is the degrees value the gun is drawn to point from pointing right. Which means that if gun have been drawn to point up the offsetDir value is 90 or -270, left the offsetDir is 180 and if down the offsetDir is -90 or 270. Edit: And to make gun to point to mouse every time the mouse is moving make mouse event event listener for mouse move and write the script above inside the handler function. Last edited by -:)lauri; 07-19-2012 at 03:36 PM.
 07-20-2012, 09:55 AM #3 GiaTuan Registered User   Join Date: Sep 2011 Location: HoChiMinh city,Vietnam Posts: 44 Thanks

 Thread Tools Display Modes Rate This Thread Hybrid Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home ActionScript Forums Group     ActionScript 3.0     ActionScript 2.0     ActionScript 1.0 (and below)     Simple Stuff (Newbies) Flash General Questions     Flash 10 General Questions     Flash 9 General Questions     Flash 8 General Questions     Other Flash General Questions Flex     Flex 2, 3 & 4     Flex 1 Extensions and Plugins     Components     JSFL - Extending Flash Desktop, Mobile and non-browser Environments     AIR (Apollo)     FlashLite / Portable Devices Development     Projectors and CDs Supporting Technologies     HTML and JavaScript     haXe     Server-Side Scripting     Flash Remoting     Flash Media Server General     Best Practices     Gaming and Game Development     Animation and Effects     Flashants Support Forum Community Boards     General Chat     Just for Kicks Challenges     Detention Flash In Action     Site Check     Cool Sites     Widgets Decommissioned     Projects and Positions CMS Forums     Announcements Board     Content Postings / Updates     Product Review Requests     CMS Technical Questions     Process Questions     Collaboration & Suggested Articles

All times are GMT. The time now is 01:23 PM.

///