<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments on: AS3 Character Movement: Asteroids Style 360 Degree Movement</title>
	<atom:link href="http://asgamer.com/2009/as3-character-movement-asteroids-style-360-degree-movement/feed" rel="self" type="application/rss+xml" />
	<link>http://asgamer.com/2009/as3-character-movement-asteroids-style-360-degree-movement</link>
	<description>Learn to Make Flash Games, Applications, and Websites</description>
	<pubDate>Sat, 31 Jul 2010 11:53:51 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Bradnon Capecci</title>
		<link>http://asgamer.com/2009/as3-character-movement-asteroids-style-360-degree-movement/comment-page-1#comment-4574</link>
		<dc:creator>Bradnon Capecci</dc:creator>
		<pubDate>Thu, 12 Nov 2009 23:54:17 +0000</pubDate>
		<guid isPermaLink="false">http://asgamer.com/?p=293#comment-4574</guid>
		<description>Use that to get the player to rotate with the mouse:
xd = this.x-stage.mouseX;
yd = this.y-stage.mouseY;
radAngle = Math.atan2(yd, xd);
this.rotation = int(radAngle*360/(Math.PI*2)-90);

Use this for creating the shots:
var shot:Shot = new Shot(stageRef);
stageRef.addChild(shot);            
shot.x = this.x;
shot.y = this.y;
shot.rotation = this.rotation;

This for moving them:
x += shotSpeed*Math.sin(rotation*(Math.PI/180));
y -= shotSpeed*Math.cos(rotation*(Math.PI/180));</description>
		<content:encoded><![CDATA[<p>Use that to get the player to rotate with the mouse:<br />
xd = this.x-stage.mouseX;<br />
yd = this.y-stage.mouseY;<br />
radAngle = Math.atan2(yd, xd);<br />
this.rotation = int(radAngle*360/(Math.PI*2)-90);</p>
<p>Use this for creating the shots:<br />
var shot:Shot = new Shot(stageRef);<br />
stageRef.addChild(shot);<br />
shot.x = this.x;<br />
shot.y = this.y;<br />
shot.rotation = this.rotation;</p>
<p>This for moving them:<br />
x += shotSpeed*Math.sin(rotation*(Math.PI/180));<br />
y -= shotSpeed*Math.cos(rotation*(Math.PI/180));</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Serax</title>
		<link>http://asgamer.com/2009/as3-character-movement-asteroids-style-360-degree-movement/comment-page-1#comment-4565</link>
		<dc:creator>Serax</dc:creator>
		<pubDate>Sat, 07 Nov 2009 02:49:35 +0000</pubDate>
		<guid isPermaLink="false">http://asgamer.com/?p=293#comment-4565</guid>
		<description>Mc :

I see what you're doing there, and I'm no expert. But I've gotten to work with mine and here's the relevant parts of my BlueLaser.as :

public function Laser (stageRef:Stage, x:Number, y:Number, rotation:Number) : void
		{
			this.stageRef = stageRef;
			this.x = x;
			this.y = y;
			this.rotation = rotation;
			
			addEventListener (Event.ENTER_FRAME, loop, false, 0, true);
		}
		
		private function loop(e:Event) : void
		{
			this.x += Math.cos(this.rotation*Math.PI/180)*speed;
			this.y += Math.sin(this.rotation*Math.PI/180)*speed;
			
			if (this.x &#62; stageRef.stageWidth)
				removeSelf();
			if (this.y &#62; stageRef.stageHeight-15)
				removeSelf();
		}</description>
		<content:encoded><![CDATA[<p>Mc :</p>
<p>I see what you&#8217;re doing there, and I&#8217;m no expert. But I&#8217;ve gotten to work with mine and here&#8217;s the relevant parts of my BlueLaser.as :</p>
<p>public function Laser (stageRef:Stage, x:Number, y:Number, rotation:Number) : void<br />
		{<br />
			this.stageRef = stageRef;<br />
			this.x = x;<br />
			this.y = y;<br />
			this.rotation = rotation;</p>
<p>			addEventListener (Event.ENTER_FRAME, loop, false, 0, true);<br />
		}</p>
<p>		private function loop(e:Event) : void<br />
		{<br />
			this.x += Math.cos(this.rotation*Math.PI/180)*speed;<br />
			this.y += Math.sin(this.rotation*Math.PI/180)*speed;</p>
<p>			if (this.x &gt; stageRef.stageWidth)<br />
				removeSelf();<br />
			if (this.y &gt; stageRef.stageHeight-15)<br />
				removeSelf();<br />
		}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mc</title>
		<link>http://asgamer.com/2009/as3-character-movement-asteroids-style-360-degree-movement/comment-page-1#comment-4563</link>
		<dc:creator>Mc</dc:creator>
		<pubDate>Fri, 30 Oct 2009 00:27:34 +0000</pubDate>
		<guid isPermaLink="false">http://asgamer.com/?p=293#comment-4563</guid>
		<description>Par..
Still trying to figure out how to face the laser to where the ship is facing. here is the code I am working on, please point me to the right direction...
for the laser:
public class LaserBlue extends MovieClip
	{
		
		private var stageRef:Stage;
		private var bulletSpeed:Number = 16;
		private var xSpeed:Number;
		private var ySpeed:Number;
		
		public function LaserBlue (stageRef:Stage, pX:Number, pY:Number, pRotation:Number)
		{
			this.stageRef = stageRef;
			x = pX;
			y = pY;
			ySpeed= Math.sin(pRotation * Math.PI / 180);
			xSpeed= Math.cos(pRotation * Math.PI / 180);
			addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
		}
		
		private function loop(e:Event) : void
		{
			//move bullet up
			x+= xSpeed;
			y+= ySpeed;
			
			if (y  stage.stageWidth)
				x = 0;
			else if (x  stage.stageHeight)
				y = 0;
			else if (y &#60; 0)
				y = stage.stageHeight;
		}
 
		public function degreesToRadians(degrees:Number) : Number
		{
			return degrees * Math.PI / 180;
			
		}
		private function fireBullet() : void
		{
			//if canFire is true, fire a bullet
			//set canFire to false and start our timer
			//else do nothing.
			if (canFire)
			{
				stageRef.addChild(new LaserBlue(stageRef, x - 40, y + vy, rotation + vx &#38;&#38;vy));
				canFire = false;
				fireTimer.start();
			}
			
		}
		
		//HANDLERS
		
		private function fireTimerHandler(e:TimerEvent) : void
		{
			//timer ran, we can fire again.
			canFire = true;
		}

	}

}
Thank you soo soo much for your help. Thank you</description>
		<content:encoded><![CDATA[<p>Par..<br />
Still trying to figure out how to face the laser to where the ship is facing. here is the code I am working on, please point me to the right direction&#8230;<br />
for the laser:<br />
public class LaserBlue extends MovieClip<br />
	{</p>
<p>		private var stageRef:Stage;<br />
		private var bulletSpeed:Number = 16;<br />
		private var xSpeed:Number;<br />
		private var ySpeed:Number;</p>
<p>		public function LaserBlue (stageRef:Stage, pX:Number, pY:Number, pRotation:Number)<br />
		{<br />
			this.stageRef = stageRef;<br />
			x = pX;<br />
			y = pY;<br />
			ySpeed= Math.sin(pRotation * Math.PI / 180);<br />
			xSpeed= Math.cos(pRotation * Math.PI / 180);<br />
			addEventListener(Event.ENTER_FRAME, loop, false, 0, true);<br />
		}</p>
<p>		private function loop(e:Event) : void<br />
		{<br />
			//move bullet up<br />
			x+= xSpeed;<br />
			y+= ySpeed;</p>
<p>			if (y  stage.stageWidth)<br />
				x = 0;<br />
			else if (x  stage.stageHeight)<br />
				y = 0;<br />
			else if (y &lt; 0)<br />
				y = stage.stageHeight;<br />
		}</p>
<p>		public function degreesToRadians(degrees:Number) : Number<br />
		{<br />
			return degrees * Math.PI / 180;</p>
<p>		}<br />
		private function fireBullet() : void<br />
		{<br />
			//if canFire is true, fire a bullet<br />
			//set canFire to false and start our timer<br />
			//else do nothing.<br />
			if (canFire)<br />
			{<br />
				stageRef.addChild(new LaserBlue(stageRef, x - 40, y + vy, rotation + vx &amp;&amp;vy));<br />
				canFire = false;<br />
				fireTimer.start();<br />
			}</p>
<p>		}</p>
<p>		//HANDLERS</p>
<p>		private function fireTimerHandler(e:TimerEvent) : void<br />
		{<br />
			//timer ran, we can fire again.<br />
			canFire = true;<br />
		}</p>
<p>	}</p>
<p>}<br />
Thank you soo soo much for your help. Thank you</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mc</title>
		<link>http://asgamer.com/2009/as3-character-movement-asteroids-style-360-degree-movement/comment-page-1#comment-4560</link>
		<dc:creator>Mc</dc:creator>
		<pubDate>Mon, 26 Oct 2009 21:56:52 +0000</pubDate>
		<guid isPermaLink="false">http://asgamer.com/?p=293#comment-4560</guid>
		<description>Thank you so much for the tutorial, I am very new to AS and is trying to build a asteroid game. You are my life saver to be so kind to post these tutorials.
I have been trying to add the laser to rotate with the ship as well. Should I add the same code to the laser file as well? Right now the laser just shoot straight up and doesn't rotate. Please give me some advice. Thank you soo much. thank you.</description>
		<content:encoded><![CDATA[<p>Thank you so much for the tutorial, I am very new to AS and is trying to build a asteroid game. You are my life saver to be so kind to post these tutorials.<br />
I have been trying to add the laser to rotate with the ship as well. Should I add the same code to the laser file as well? Right now the laser just shoot straight up and doesn&#8217;t rotate. Please give me some advice. Thank you soo much. thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Par</title>
		<link>http://asgamer.com/2009/as3-character-movement-asteroids-style-360-degree-movement/comment-page-1#comment-4546</link>
		<dc:creator>Par</dc:creator>
		<pubDate>Wed, 07 Oct 2009 13:07:11 +0000</pubDate>
		<guid isPermaLink="false">http://asgamer.com/?p=293#comment-4546</guid>
		<description>@jaybdemented.
Yes that will work but it will also completely alter the way the ship moves. The sliding effect will no longer work the same way.</description>
		<content:encoded><![CDATA[<p>@jaybdemented.<br />
Yes that will work but it will also completely alter the way the ship moves. The sliding effect will no longer work the same way.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jaybdemented</title>
		<link>http://asgamer.com/2009/as3-character-movement-asteroids-style-360-degree-movement/comment-page-1#comment-4540</link>
		<dc:creator>jaybdemented</dc:creator>
		<pubDate>Sat, 03 Oct 2009 12:12:18 +0000</pubDate>
		<guid isPermaLink="false">http://asgamer.com/?p=293#comment-4540</guid>
		<description>a easier way to set the max speed.

private var speed:Number = 10;

and change
vy += Math.sin(degreesToRadians(rotation)) * speed;
vx += Math.cos(degreesToRadians(rotation)) * speed;
to this
vy = Math.sin(degreesToRadians(rotation)) * speed;
vx = Math.cos(degreesToRadians(rotation)) * speed;</description>
		<content:encoded><![CDATA[<p>a easier way to set the max speed.</p>
<p>private var speed:Number = 10;</p>
<p>and change<br />
vy += Math.sin(degreesToRadians(rotation)) * speed;<br />
vx += Math.cos(degreesToRadians(rotation)) * speed;<br />
to this<br />
vy = Math.sin(degreesToRadians(rotation)) * speed;<br />
vx = Math.cos(degreesToRadians(rotation)) * speed;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aaron</title>
		<link>http://asgamer.com/2009/as3-character-movement-asteroids-style-360-degree-movement/comment-page-1#comment-4423</link>
		<dc:creator>Aaron</dc:creator>
		<pubDate>Mon, 27 Jul 2009 05:34:39 +0000</pubDate>
		<guid isPermaLink="false">http://asgamer.com/?p=293#comment-4423</guid>
		<description>Good starting point, but this lacks any sort of maximum speed, so if you hold down thrust you get going insanely fast really quickly. To make a game out of it you need to have some sort of speed limit, like this:

// enforce speed limit - find length of vector 
// and scale down to maxSpeed if necessary
var currentSpeed:Number = Math.sqrt((vx * vx) + (vy * vy));
if(currentSpeed &#62; maxSpeed){
	vx *= maxSpeed / currentSpeed;
	vy *= maxSpeed / currentSpeed;
}</description>
		<content:encoded><![CDATA[<p>Good starting point, but this lacks any sort of maximum speed, so if you hold down thrust you get going insanely fast really quickly. To make a game out of it you need to have some sort of speed limit, like this:</p>
<p>// enforce speed limit - find length of vector<br />
// and scale down to maxSpeed if necessary<br />
var currentSpeed:Number = Math.sqrt((vx * vx) + (vy * vy));<br />
if(currentSpeed &gt; maxSpeed){<br />
	vx *= maxSpeed / currentSpeed;<br />
	vy *= maxSpeed / currentSpeed;<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ascendist</title>
		<link>http://asgamer.com/2009/as3-character-movement-asteroids-style-360-degree-movement/comment-page-1#comment-2340</link>
		<dc:creator>Ascendist</dc:creator>
		<pubDate>Mon, 25 May 2009 00:52:10 +0000</pubDate>
		<guid isPermaLink="false">http://asgamer.com/?p=293#comment-2340</guid>
		<description>Sorry, I'm really new to as3 lol, but what would the best method of going about this be?:

Making the ship rotate like normal, but moving a larget background MC in the opposite directions again for a large scale map style game?

would just need an example of the movement snippet for bg mc.</description>
		<content:encoded><![CDATA[<p>Sorry, I&#8217;m really new to as3 lol, but what would the best method of going about this be?:</p>
<p>Making the ship rotate like normal, but moving a larget background MC in the opposite directions again for a large scale map style game?</p>
<p>would just need an example of the movement snippet for bg mc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ramon Fritsch</title>
		<link>http://asgamer.com/2009/as3-character-movement-asteroids-style-360-degree-movement/comment-page-1#comment-1827</link>
		<dc:creator>Ramon Fritsch</dc:creator>
		<pubDate>Tue, 12 May 2009 00:48:50 +0000</pubDate>
		<guid isPermaLink="false">http://asgamer.com/?p=293#comment-1827</guid>
		<description>Nice man.

You can put the gravity too. Its more realistic

Great tutorial. cheers</description>
		<content:encoded><![CDATA[<p>Nice man.</p>
<p>You can put the gravity too. Its more realistic</p>
<p>Great tutorial. cheers</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Samuel L.</title>
		<link>http://asgamer.com/2009/as3-character-movement-asteroids-style-360-degree-movement/comment-page-1#comment-1013</link>
		<dc:creator>Samuel L.</dc:creator>
		<pubDate>Wed, 22 Apr 2009 06:59:40 +0000</pubDate>
		<guid isPermaLink="false">http://asgamer.com/?p=293#comment-1013</guid>
		<description>Not that I'm totally impressed, but this is a lot more than I expected for when I stumpled upon a link on Digg telling that the info here is awesome. Thanks.</description>
		<content:encoded><![CDATA[<p>Not that I&#8217;m totally impressed, but this is a lot more than I expected for when I stumpled upon a link on Digg telling that the info here is awesome. Thanks.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
