Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-19-2012, 08:57 AM   #1
GiaTuan
Registered User
 
Join Date: Sep 2011
Location: HoChiMinh city,Vietnam
Posts: 44
Question [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.
GiaTuan is offline   Reply With Quote
Old 07-19-2012, 03:28 PM   #2
-:)lauri
Senior Member
 
Join Date: Aug 2008
Location: Helsinki, Finland
Posts: 1,184
Default

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.
-:)lauri is offline   Reply With Quote
Old 07-20-2012, 09:55 AM   #3
GiaTuan
Registered User
 
Join Date: Sep 2011
Location: HoChiMinh city,Vietnam
Posts: 44
Default

Thanks
GiaTuan is offline   Reply With Quote
Reply


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 01:22 AM.

///
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.