Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > General > Gaming and Game Development

Reply
 
Thread Tools Rate Thread Display Modes
Old 12-23-2010, 05:43 PM   #1
Scearezt
Satisfied User
 
Scearezt's Avatar
 
Join Date: Jun 2010
Location: C:\\System32\Hungary
Posts: 426
Question [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?
Scearezt is offline   Reply With Quote
Old 12-23-2010, 07:04 PM   #2
Orcist
Registered User
 
Join Date: Nov 2010
Posts: 30
Default

in 2d you mean that you want your movieclip go up and down after pressing down the up and down keys?
Orcist is offline   Reply With Quote
Old 12-23-2010, 09:19 PM   #3
rrh
throw a trace() in there
 
Join Date: Dec 2006
Posts: 1,982
Default

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.
rrh is offline   Reply With Quote
Old 12-24-2010, 07:48 AM   #4
Orcist
Registered User
 
Join Date: Nov 2010
Posts: 30
Default

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....
Orcist is offline   Reply With Quote
Old 12-24-2010, 02:37 PM   #5
Scearezt
Satisfied User
 
Scearezt's Avatar
 
Join Date: Jun 2010
Location: C:\\System32\Hungary
Posts: 426
Smile

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
Scearezt is offline   Reply With Quote
Old 12-25-2010, 04:50 PM   #6
zyxstand
Platinum Member
 
Join Date: Dec 2010
Posts: 193
Default

Quote:
Originally Posted by Scearezt View Post
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).
zyxstand is offline   Reply With Quote
Old 12-26-2010, 07:52 PM   #7
Scearezt
Satisfied User
 
Scearezt's Avatar
 
Join Date: Jun 2010
Location: C:\\System32\Hungary
Posts: 426
Default

Um... I don't need this code thanks... I don't want my MC to rotate toward my mouse... also I knew it..
Scearezt is offline   Reply With Quote
Old 12-26-2010, 08:38 PM   #8
zyxstand
Platinum Member
 
Join Date: Dec 2010
Posts: 193
Default

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
zyxstand 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 04:14 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.