Home Tutorials Forums Articles Blogs Movies Library Employment Press

 ActionScript.org Forums [AS2] MC Goes toward it's Angle
 Register FAQ Members List Social Groups Calendar Search Today's Posts Mark Forums Read

 12-23-2010, 05:43 PM #1 Scearezt Satisfied User     Join Date: Jun 2010 Location: C:\\System32\Hungary Posts: 426 [AS2] MC Goes toward it's Angle So my problem is the next.... I can't get my MC go toward his angle... I can move my MC with the UP-DOWN arrow keys and it's rotating when I hold down the RIGHT-LEFT arrow keys... but I want to move with the UP(toward) and DOWN(backward) keys wherever it occurs... any Idea how?
 12-23-2010, 07:04 PM #2 Orcist Registered User   Join Date: Nov 2010 Posts: 30 in 2d you mean that you want your movieclip go up and down after pressing down the up and down keys?
 12-23-2010, 09:19 PM #3 rrh throw a trace() in there   Join Date: Dec 2006 Posts: 1,982 I assume he means forward and backwards according to the direction it's facing. Like Asteroids. Code: ```x+=Math.sin(rotation converted to radians)*speed; y+=Math.cos(rotation converted to radians)*speed;``` Or I could have sin and cos backwards, I always get them confused.
 12-24-2010, 07:48 AM #4 Orcist Registered User   Join Date: Nov 2010 Posts: 30 yes i think that the first one is correct...scearezt try it it should help you...and if its reverted witih that sin and cos just replace them....
 12-24-2010, 02:37 PM #5 Scearezt Satisfied User     Join Date: Jun 2010 Location: C:\\System32\Hungary Posts: 426 Yeah I got it! Thanks guys! Final Code: ActionScript Code: ```MC._y-=Math.cos(Math.PI/180 * MC._rotation) * speed;         MC._x+=Math.sin(Math.PI/180 * MC._rotation) * speed```
12-25-2010, 04:50 PM   #6
zyxstand
Platinum Member

Join Date: Dec 2010
Posts: 193

Quote:
 Originally Posted by Scearezt Yeah I got it! Thanks guys! Final Code: ActionScript Code: ```MC._y-=Math.cos(Math.PI/180 * MC._rotation) * speed;         MC._x+=Math.sin(Math.PI/180 * MC._rotation) * speed```
just to let you know, your _x should be cos and _y should be sine. the problem is that the direction of your sprite as you create it should be 0 degrees which, in flash (and in math and in general) is to the RIGHT.
your code for rotation should also follow:
Code:
`mc._rotation = Math.atan2(mouse._y - mc_y, mouse_x - mc_x);`
stick to this and your code will make sense and you won't have to resolve things by trial and error (as it seems you've done here).

 12-26-2010, 07:52 PM #7 Scearezt Satisfied User     Join Date: Jun 2010 Location: C:\\System32\Hungary Posts: 426 Um... I don't need this code thanks... I don't want my MC to rotate toward my mouse... also I knew it..
 12-26-2010, 08:38 PM #8 zyxstand Platinum Member   Join Date: Dec 2010 Posts: 193 oh sry i misread stuff. my point still remains: you should draw your sprites so that facing right is 0 degrees, and you can use y=sin(rotation)*speed and x=cos(rotation)*speed the way it should be

 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 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 12:20 AM.

///