<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Andrew Natoli &#187; Programming</title>
	<atom:link href="http://andrewnatoli.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewnatoli.com</link>
	<description></description>
	<lastBuildDate>Thu, 08 Dec 2011 03:02:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Projectile Speed on Mouse Position</title>
		<link>http://andrewnatoli.com/2008/10/projectile-speed-on-mouse-position/</link>
		<comments>http://andrewnatoli.com/2008/10/projectile-speed-on-mouse-position/#comments</comments>
		<pubDate>Sun, 19 Oct 2008 23:47:46 +0000</pubDate>
		<dc:creator>Andrew Natoli</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Game Maker 7]]></category>
		<category><![CDATA[GML]]></category>
		<category><![CDATA[Resources]]></category>

		<guid isPermaLink="false">http://andrewnatoli.com/?p=103</guid>
		<description><![CDATA[Something I’ve been working on lately in one of my games is working in dynamic projectile speeds so players can strategically toss grenades to where they need to go rather than having to find some way to make the default speed work for them. So in my case, a player wants to throw a grenade [...]]]></description>
			<content:encoded><![CDATA[<p>Something I’ve been working on lately in one of my games is working in dynamic projectile speeds so players can strategically toss grenades to where they need to go rather than having to find some way to make the default speed work for them. So in my case, a player wants to throw a grenade to where their cursor is positioned. What I did was set up the angle calculations which is the easy part, though then there’s speed afterwards.<span id="more-103"></span></p>
<pre><code>var mspd; //Creates the temporary value, mspd
mspd =(point_distance(x,y,mouse_x,mouse_y)/16); //Sets mspd to our needed speed
</code></pre>
<p>The above GML finds the distance between the source of the projectile and your mouse cursor, then divides by 16 to adjust the returned value to a usable speed (otherwise it’d go quite fast) This is how I used the code in my game:</p>
<pre><code>var plyspd, gspd;
plyspd = o_player.hsp //Horizontal Speed of My Character
if plyspd &lt; 0 { plyspd=plyspd*-1; } //If player is moving backwards, switch negative speed to positive
gspd = plyspd+(point_distance(x,y,mouse_x,mouse_y)/16) //Speed will be the calculated speed PLUS the speed the player is moving at
if gspd &gt; (18.92)+plyspd { gspd = (18.92)+plyspd; } //Keeps the projectile from going rediculously fast by setting a limit plus the player's current speed</code></pre>
<p style="text-align: center;"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/x3rWcUurtbs&amp;hl=en&amp;fs=1&amp;color1=0x234900&amp;color2=0x4e9e00" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/x3rWcUurtbs&amp;hl=en&amp;fs=1&amp;color1=0x234900&amp;color2=0x4e9e00" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewnatoli.com/2008/10/projectile-speed-on-mouse-position/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

