Home Tutorials Forums Articles Blogs Movies Library Employment Press

 ActionScript.org Forums Move movieClip towards rotation angle
 Register FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

 01-22-2008, 04:44 AM #1 XaeroDegreaz www.smartsocket.net   Join Date: Apr 2007 Posts: 150 Move movieClip towards rotation angle Hi, I'm trying to move a movieClip based on it's _rotation property. I have a little triangle that could represent a spaceship perhaps. If the triangle is facing up (0 degrees) I want it to move straight up when I press the UP key. If it is facing 45 degrees, I want it to move forward in that direction. Could someone help me with the math involved in moving a movieClip towards its rotation angle? Thanks in advance.
 01-22-2008, 04:52 AM #2 Durnus Senior Member   Join Date: Mar 2007 Posts: 257 Okay, I'll give this a shot. Pretty simple, I just get my directions messed up a lot Someone can fix this if they want to, but this is basically it: Code: //Let's assume your movieclip is called MC, and you changed _rotation to change your object's angle. //Say, this var represents distance in pixels. var SPEED = 5; //It would be one pair of these two lines, I'm not sure which: MC._x += Math.cos(MC._rotation)*SPEED; MC._y += Math.sin(MC._rotation)*SPEED; //or MC._x += Math.cos(MC._rotation/180*Math.PI)*SPEED; MC._y += Math.sin(MC._rotation/180*Math.PI)*SPEED; But, just so you know: Up is not zero degrees. Right is. I think down is 90, and it goes around that way, but I'm not sure. I hope my code helped, it probably won't work, but at least it's something.
 01-22-2008, 04:59 AM #3 XaeroDegreaz www.smartsocket.net   Join Date: Apr 2007 Posts: 150 Yeah, I kinda have something like that. I can tell it's trying to work, because the triangle does change directions based on angle. However, it doesn't go the correct way
 01-22-2008, 05:02 AM #4 ASWC Super Moderator     Join Date: Dec 2007 Location: Greenville, SC Posts: 6,742 speedx =Math.sin(this._rotation*(Math.PI/180))*2; speedy = Math.cos(this._rotation*(Math.PI/180))*2*-1; this._x+=speedx*speed; this._y+=speedy*speed; Use what you want as a "speed" variable. __________________ aswebcreations Super Duper!
 01-22-2008, 05:04 AM #5 XaeroDegreaz www.smartsocket.net   Join Date: Apr 2007 Posts: 150 You the man brotha. That's exactly what I needed! Thanks a lot
 01-22-2008, 05:09 AM #6 ASWC Super Moderator     Join Date: Dec 2007 Location: Greenville, SC Posts: 6,742 Hey Durnus, just so you know the _rotation in Flash output values from -180 to 180, instead of from 0 to 360, so when writing function for that you have to translate everything into values you can use. __________________ aswebcreations Super Duper!
 01-22-2008, 05:13 AM #7 Durnus Senior Member   Join Date: Mar 2007 Posts: 257 I didn't know that, but cos(180+90) would output the same out cos(-90), correct? (Assuming we are using degree mode.) So therefore, how did you know I didn't know it was from -180 to 180? :P You did catch the - for the y. I didn't get that, I always debug the signs after I write the whole thing. I never get stuff right the first time.
 01-22-2008, 05:17 AM #8 ASWC Super Moderator     Join Date: Dec 2007 Location: Greenville, SC Posts: 6,742 I just do a lot of stuff like that in Flash. I knew you didn't know since your code couldn't work but was close enough. In fact if you add 180 then you have a 0 to 360. __________________ aswebcreations Super Duper!
 01-22-2008, 05:20 AM #9 XaeroDegreaz www.smartsocket.net   Join Date: Apr 2007 Posts: 150 Now I need to come up with something clean for acceleration and deceleration. -_- Man, I hate math. Most I do in math is count grams and ounces.
 01-22-2008, 05:21 AM #10 ASWC Super Moderator     Join Date: Dec 2007 Location: Greenville, SC Posts: 6,742 By the way I can tell you are doing a Asteroid clone, am I right? __________________ aswebcreations Super Duper!

 Thread Tools Display Modes Rate This Thread Linear 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 Off 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

 Similar Threads Thread Thread Starter Forum Replies Last Post saravanan ActionScript 2.0 0 06-01-2007 11:08 AM Haso2000 ActionScript 1.0 (and below) 7 03-27-2007 04:27 PM connman ActionScript 2.0 2 10-28-2005 01:44 AM monkeybrainz ActionScript 1.0 (and below) 1 08-02-2004 12:46 PM Didd ActionScript 1.0 (and below) 12 06-29-2003 05:15 PM

All times are GMT. The time now is 03:07 AM.

///