<?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: Calculating heading in 2d games: Using trigonometric functions part 1</title>
	<atom:link href="https://gamecodeschool.com/essentials/calculating-heading-in-2d-games-using-trigonometric-functions-part-1/feed/" rel="self" type="application/rss+xml" />
	<link>https://gamecodeschool.com/essentials/calculating-heading-in-2d-games-using-trigonometric-functions-part-1/</link>
	<description>Game Coding for Beginners</description>
	<lastBuildDate>Mon, 20 Apr 2026 12:04:35 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.2.38</generator>
	<item>
		<title>By: John Horton</title>
		<link>https://gamecodeschool.com/essentials/calculating-heading-in-2d-games-using-trigonometric-functions-part-1/#comment-4568</link>
		<dc:creator><![CDATA[John Horton]]></dc:creator>
		<pubDate>Sat, 18 Feb 2017 17:51:06 +0000</pubDate>
		<guid isPermaLink="false">http://gamecodeschool.com/?p=12113#comment-4568</guid>
		<description><![CDATA[Glad to be of help! The code is from the next project in the course.]]></description>
		<content:encoded><![CDATA[<p>Glad to be of help! The code is from the next project in the course.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John H</title>
		<link>https://gamecodeschool.com/essentials/calculating-heading-in-2d-games-using-trigonometric-functions-part-1/#comment-4549</link>
		<dc:creator><![CDATA[John H]]></dc:creator>
		<pubDate>Fri, 17 Feb 2017 23:38:17 +0000</pubDate>
		<guid isPermaLink="false">http://gamecodeschool.com/?p=12113#comment-4549</guid>
		<description><![CDATA[Thanks John, I am so grateful that you have this website, you are helping beginners step into game programming much easier. I have asked other &quot;pro&quot; programmers this same question I asked you and they just gave vague answers or were just plain lazy in explaining, while making me feel like an idiot in the process. You actually posted code to show the procedure, which has helped me more then anyone else...it boggles me why experienced programmers would act like this....... i have been searching for an answer from google and other people for like 3 weeks with no success. thank you so much, i am also still working through the udemy beginner c++ course still tinkering with timberman.]]></description>
		<content:encoded><![CDATA[<p>Thanks John, I am so grateful that you have this website, you are helping beginners step into game programming much easier. I have asked other &#8220;pro&#8221; programmers this same question I asked you and they just gave vague answers or were just plain lazy in explaining, while making me feel like an idiot in the process. You actually posted code to show the procedure, which has helped me more then anyone else&#8230;it boggles me why experienced programmers would act like this&#8230;&#8230;. i have been searching for an answer from google and other people for like 3 weeks with no success. thank you so much, i am also still working through the udemy beginner c++ course still tinkering with timberman.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Horton</title>
		<link>https://gamecodeschool.com/essentials/calculating-heading-in-2d-games-using-trigonometric-functions-part-1/#comment-4539</link>
		<dc:creator><![CDATA[John Horton]]></dc:creator>
		<pubDate>Fri, 17 Feb 2017 10:08:20 +0000</pubDate>
		<guid isPermaLink="false">http://gamecodeschool.com/?p=12113#comment-4539</guid>
		<description><![CDATA[Are you trying to calculate the direction between the two objects to shoot from one to the other? If so you need to calculate the ratio of the rate of change between horizontal and vertical. This can then form a horizontal and vertical speed(or gradient). Here is a copy &amp; paste from the shoot function of a Bullet class I used to shoot bullets from the player to a movable crosshair. Hope this helps a bit.

&lt;code&gt;void Bullet::shoot(float startX, float startY,&lt;/code&gt;
    &lt;code&gt;float targetX, float targetY)&lt;/code&gt;
&lt;code&gt;{&lt;/code&gt;
    &lt;code&gt;// Keep track of the bullet&lt;/code&gt;
    &lt;code&gt;m_InFlight = true;&lt;/code&gt;
    &lt;code&gt;m_Position.x = startX;&lt;/code&gt;
    &lt;code&gt;m_Position.y = startY;&lt;/code&gt;
 
    &lt;code&gt;// Calculate the gradient of the flight path&lt;/code&gt;
    &lt;code&gt;float gradient = (startX - targetX) / (startY - targetY);&lt;/code&gt;
 
    &lt;code&gt;// Any gradient less than zero needs to be negative&lt;/code&gt;
    &lt;code&gt;if (gradient &lt; 0)&lt;/code&gt;
    &lt;code&gt;{&lt;/code&gt;
        &lt;code&gt;gradient *= -1;&lt;/code&gt;
    &lt;code&gt;}&lt;/code&gt;
 
    &lt;code&gt;// Calculate the ratio between x and t&lt;/code&gt;
    &lt;code&gt;float ratioXY = m_BulletSpeed / (1 + gradient);&lt;/code&gt;
 
    &lt;code&gt;// Set the &quot;speed&quot; horizontally and vertically&lt;/code&gt;
    &lt;code&gt;m_BulletDistanceY = ratioXY;&lt;/code&gt;
    &lt;code&gt;m_BulletDistanceX = ratioXY * gradient;&lt;/code&gt;
     
    &lt;code&gt;// Point the bullet in the right direction&lt;/code&gt;
    &lt;code&gt;if (targetX &lt; startX)&lt;/code&gt;
    &lt;code&gt;{&lt;/code&gt;
        &lt;code&gt;m_BulletDistanceX *= -1;&lt;/code&gt;
    &lt;code&gt;}&lt;/code&gt;
 
    &lt;code&gt;if (targetY &lt; startY)&lt;/code&gt;
    &lt;code&gt;{&lt;/code&gt;
        &lt;code&gt;m_BulletDistanceY *= -1;&lt;/code&gt;
    &lt;code&gt;}&lt;/code&gt;
 
    &lt;code&gt;// Finally, assign the results to the&lt;/code&gt;
    &lt;code&gt;// member variables&lt;/code&gt;
    &lt;code&gt;m_XTarget = targetX;&lt;/code&gt;
    &lt;code&gt;m_YTarget = targetY;&lt;/code&gt;
 
    &lt;code&gt;// Set a max range of 1000 pixels&lt;/code&gt;
    &lt;code&gt;float range = 1000;&lt;/code&gt;
    &lt;code&gt;m_MinX = startX - range;&lt;/code&gt;
    &lt;code&gt;m_MaxX = startX + range;&lt;/code&gt;
    &lt;code&gt;m_MinY = startY - range;&lt;/code&gt;
    &lt;code&gt;m_MaxY = startY + range;&lt;/code&gt;
     
    &lt;code&gt;// Position the bullet ready to be drawn&lt;/code&gt;
    &lt;code&gt;m_BulletShape.setPosition(m_Position);&lt;/code&gt;
&lt;code&gt;}&lt;/code&gt;]]></description>
		<content:encoded><![CDATA[<p>Are you trying to calculate the direction between the two objects to shoot from one to the other? If so you need to calculate the ratio of the rate of change between horizontal and vertical. This can then form a horizontal and vertical speed(or gradient). Here is a copy &#038; paste from the shoot function of a Bullet class I used to shoot bullets from the player to a movable crosshair. Hope this helps a bit.</p>
<p>
			<span id="crayon-69eac2e9ee70f729199460" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-t">void</span><span class="crayon-h"> </span><span class="crayon-v">Bullet</span><span class="crayon-o">::</span><span class="crayon-v">shoot</span><span class="crayon-sy">(</span><span class="crayon-t">float</span><span class="crayon-h"> </span><span class="crayon-v">startX</span><span class="crayon-sy">,</span><span class="crayon-h"> </span><span class="crayon-t">float</span><span class="crayon-h"> </span><span class="crayon-v">startY</span><span class="crayon-sy">,</span></span></span><br />
    
			<span id="crayon-69eac2e9ee715180880212" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-t">float</span><span class="crayon-h"> </span><span class="crayon-v">targetX</span><span class="crayon-sy">,</span><span class="crayon-h"> </span><span class="crayon-t">float</span><span class="crayon-h"> </span><span class="crayon-v">targetY</span><span class="crayon-sy">)</span></span></span><br />

			<span id="crayon-69eac2e9ee717157548044" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-sy">{</span></span></span><br />
    
			<span id="crayon-69eac2e9ee719762565549" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-c">// Keep track of the bullet</span></span></span><br />
    
			<span id="crayon-69eac2e9ee71b858614450" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">m_InFlight</span><span class="crayon-h"> </span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-t">true</span><span class="crayon-sy">;</span></span></span><br />
    
			<span id="crayon-69eac2e9ee71d396971182" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">m_Position</span><span class="crayon-sy">.</span><span class="crayon-v">x</span><span class="crayon-h"> </span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-v">startX</span><span class="crayon-sy">;</span></span></span><br />
    
			<span id="crayon-69eac2e9ee71f910390626" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">m_Position</span><span class="crayon-sy">.</span><span class="crayon-v">y</span><span class="crayon-h"> </span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-v">startY</span><span class="crayon-sy">;</span></span></span></p>
<p>    
			<span id="crayon-69eac2e9ee721865512383" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-c">// Calculate the gradient of the flight path</span></span></span><br />
    
			<span id="crayon-69eac2e9ee723844739296" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-t">float</span><span class="crayon-h"> </span><span class="crayon-v">gradient</span><span class="crayon-h"> </span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-sy">(</span><span class="crayon-v">startX</span><span class="crayon-h"> </span><span class="crayon-o">-</span><span class="crayon-h"> </span><span class="crayon-v">targetX</span><span class="crayon-sy">)</span><span class="crayon-h"> </span><span class="crayon-o">/</span><span class="crayon-h"> </span><span class="crayon-sy">(</span><span class="crayon-v">startY</span><span class="crayon-h"> </span><span class="crayon-o">-</span><span class="crayon-h"> </span><span class="crayon-v">targetY</span><span class="crayon-sy">)</span><span class="crayon-sy">;</span></span></span></p>
<p>    
			<span id="crayon-69eac2e9ee725229299420" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-c">// Any gradient less than zero needs to be negative</span></span></span><br />
    
			<span id="crayon-69eac2e9ee728482634739" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-st">if</span><span class="crayon-h"> </span><span class="crayon-sy">(</span><span class="crayon-v">gradient</span><span class="crayon-h"> </span><span class="crayon-o">&lt;</span><span class="crayon-h"> </span><span class="crayon-cn">0</span><span class="crayon-sy">)</span></span></span><br />
    
			<span id="crayon-69eac2e9ee729297562291" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-sy">{</span></span></span><br />
        
			<span id="crayon-69eac2e9ee72c410406024" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-e ">gradient *</span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-o">-</span><span class="crayon-cn">1</span><span class="crayon-sy">;</span></span></span><br />
    
			<span id="crayon-69eac2e9ee72e308535413" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-sy">}</span></span></span></p>
<p>    
			<span id="crayon-69eac2e9ee730542085296" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-c">// Calculate the ratio between x and t</span></span></span><br />
    
			<span id="crayon-69eac2e9ee732558269507" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-t">float</span><span class="crayon-h"> </span><span class="crayon-v">ratioXY</span><span class="crayon-h"> </span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-v">m_BulletSpeed</span><span class="crayon-h"> </span><span class="crayon-o">/</span><span class="crayon-h"> </span><span class="crayon-sy">(</span><span class="crayon-cn">1</span><span class="crayon-h"> </span><span class="crayon-o">+</span><span class="crayon-h"> </span><span class="crayon-v">gradient</span><span class="crayon-sy">)</span><span class="crayon-sy">;</span></span></span></p>
<p>    
			<span id="crayon-69eac2e9ee734636485451" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-c">// Set the "speed" horizontally and vertically</span></span></span><br />
    
			<span id="crayon-69eac2e9ee737397415282" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">m_BulletDistanceY</span><span class="crayon-h"> </span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-v">ratioXY</span><span class="crayon-sy">;</span></span></span><br />
    
			<span id="crayon-69eac2e9ee739441498171" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">m_BulletDistanceX</span><span class="crayon-h"> </span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-e ">ratioXY *</span><span class="crayon-h"> </span><span class="crayon-v">gradient</span><span class="crayon-sy">;</span></span></span></p>
<p>    
			<span id="crayon-69eac2e9ee73b348915357" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-c">// Point the bullet in the right direction</span></span></span><br />
    
			<span id="crayon-69eac2e9ee73d518318648" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-st">if</span><span class="crayon-h"> </span><span class="crayon-sy">(</span><span class="crayon-v">targetX</span><span class="crayon-h"> </span><span class="crayon-o">&lt;</span><span class="crayon-h"> </span><span class="crayon-v">startX</span><span class="crayon-sy">)</span></span></span><br />
    
			<span id="crayon-69eac2e9ee73f808110967" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-sy">{</span></span></span><br />
        
			<span id="crayon-69eac2e9ee741546203581" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-e ">m_BulletDistanceX *</span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-o">-</span><span class="crayon-cn">1</span><span class="crayon-sy">;</span></span></span><br />
    
			<span id="crayon-69eac2e9ee743634262942" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-sy">}</span></span></span></p>
<p>    
			<span id="crayon-69eac2e9ee745218342282" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-st">if</span><span class="crayon-h"> </span><span class="crayon-sy">(</span><span class="crayon-v">targetY</span><span class="crayon-h"> </span><span class="crayon-o">&lt;</span><span class="crayon-h"> </span><span class="crayon-v">startY</span><span class="crayon-sy">)</span></span></span><br />
    
			<span id="crayon-69eac2e9ee747306596821" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-sy">{</span></span></span><br />
        
			<span id="crayon-69eac2e9ee74a594495758" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-e ">m_BulletDistanceY *</span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-o">-</span><span class="crayon-cn">1</span><span class="crayon-sy">;</span></span></span><br />
    
			<span id="crayon-69eac2e9ee74c883809036" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-sy">}</span></span></span></p>
<p>    
			<span id="crayon-69eac2e9ee74e762243020" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-c">// Finally, assign the results to the</span></span></span><br />
    
			<span id="crayon-69eac2e9ee750723889109" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-c">// member variables</span></span></span><br />
    
			<span id="crayon-69eac2e9ee752060056581" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">m_XTarget</span><span class="crayon-h"> </span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-v">targetX</span><span class="crayon-sy">;</span></span></span><br />
    
			<span id="crayon-69eac2e9ee754788936536" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">m_YTarget</span><span class="crayon-h"> </span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-v">targetY</span><span class="crayon-sy">;</span></span></span></p>
<p>    
			<span id="crayon-69eac2e9ee756499872044" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-c">// Set a max range of 1000 pixels</span></span></span><br />
    
			<span id="crayon-69eac2e9ee758434317270" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-t">float</span><span class="crayon-h"> </span><span class="crayon-v">range</span><span class="crayon-h"> </span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-cn">1000</span><span class="crayon-sy">;</span></span></span><br />
    
			<span id="crayon-69eac2e9ee75b379066347" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">m_MinX</span><span class="crayon-h"> </span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-v">startX</span><span class="crayon-h"> </span><span class="crayon-o">-</span><span class="crayon-h"> </span><span class="crayon-v">range</span><span class="crayon-sy">;</span></span></span><br />
    
			<span id="crayon-69eac2e9ee75d511318064" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">m_MaxX</span><span class="crayon-h"> </span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-v">startX</span><span class="crayon-h"> </span><span class="crayon-o">+</span><span class="crayon-h"> </span><span class="crayon-v">range</span><span class="crayon-sy">;</span></span></span><br />
    
			<span id="crayon-69eac2e9ee75f336381556" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">m_MinY</span><span class="crayon-h"> </span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-v">startY</span><span class="crayon-h"> </span><span class="crayon-o">-</span><span class="crayon-h"> </span><span class="crayon-v">range</span><span class="crayon-sy">;</span></span></span><br />
    
			<span id="crayon-69eac2e9ee761788299767" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">m_MaxY</span><span class="crayon-h"> </span><span class="crayon-o">=</span><span class="crayon-h"> </span><span class="crayon-v">startY</span><span class="crayon-h"> </span><span class="crayon-o">+</span><span class="crayon-h"> </span><span class="crayon-v">range</span><span class="crayon-sy">;</span></span></span></p>
<p>    
			<span id="crayon-69eac2e9ee763774225561" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-c">// Position the bullet ready to be drawn</span></span></span><br />
    
			<span id="crayon-69eac2e9ee765813431402" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-v">m_BulletShape</span><span class="crayon-sy">.</span><span class="crayon-e">setPosition</span><span class="crayon-sy">(</span><span class="crayon-v">m_Position</span><span class="crayon-sy">)</span><span class="crayon-sy">;</span></span></span><br />

			<span id="crayon-69eac2e9ee767232459604" class="crayon-syntax crayon-syntax-inline  crayon-theme-classic crayon-theme-classic-inline crayon-font-droid-sans-mono" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important;"><span class="crayon-pre crayon-code" style="font-size: 12px !important; line-height: 16px !important;font-size: 12px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;"><span class="crayon-sy">}</span></span></span></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John H</title>
		<link>https://gamecodeschool.com/essentials/calculating-heading-in-2d-games-using-trigonometric-functions-part-1/#comment-4536</link>
		<dc:creator><![CDATA[John H]]></dc:creator>
		<pubDate>Fri, 17 Feb 2017 07:20:42 +0000</pubDate>
		<guid isPermaLink="false">http://gamecodeschool.com/?p=12113#comment-4536</guid>
		<description><![CDATA[Hi John, I have been working on a project (tank) shooter, I have 2 circles on the screen, but I am having problems making my enemy shoot when player is on the left, right, top, or below the enemy. I cant seem to get it working, I tried using 

int angle = atan2(mEnemy.getPosition().y - mPlayer.getPosition().y, mEnemy.getPosition().x - mPlayer.getPosition().x);
angle = angle * (180 / PI);
std::cout &lt;&lt; &quot;Value is&quot; &lt;&lt; angle &lt;&lt; &quot;\n&quot;;

I am using SFML...........any tips to point in the the right direction?
I also have had angle as a double but it gives weird output. How would I go about doing this, I created a picture imgur to show what I am talking about, any help in direction on how to solve this problem? in short I want the enemy to shoot towards the player wherever he is on screen. here is a pic http://imgur.com/a/YDait]]></description>
		<content:encoded><![CDATA[<p>Hi John, I have been working on a project (tank) shooter, I have 2 circles on the screen, but I am having problems making my enemy shoot when player is on the left, right, top, or below the enemy. I cant seem to get it working, I tried using </p>
<p>int angle = atan2(mEnemy.getPosition().y &#8211; mPlayer.getPosition().y, mEnemy.getPosition().x &#8211; mPlayer.getPosition().x);<br />
angle = angle * (180 / PI);<br />
std::cout &lt;&lt; &quot;Value is&quot; &lt;&lt; angle &lt;&lt; &quot;\n&quot;;</p>
<p>I am using SFML&#8230;&#8230;&#8230;..any tips to point in the the right direction?<br />
I also have had angle as a double but it gives weird output. How would I go about doing this, I created a picture imgur to show what I am talking about, any help in direction on how to solve this problem? in short I want the enemy to shoot towards the player wherever he is on screen. here is a pic <a href="http://imgur.com/a/YDait" rel="nofollow">http://imgur.com/a/YDait</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Horton</title>
		<link>https://gamecodeschool.com/essentials/calculating-heading-in-2d-games-using-trigonometric-functions-part-1/#comment-3172</link>
		<dc:creator><![CDATA[John Horton]]></dc:creator>
		<pubDate>Sun, 06 Nov 2016 12:28:44 +0000</pubDate>
		<guid isPermaLink="false">http://gamecodeschool.com/?p=12113#comment-3172</guid>
		<description><![CDATA[Zero degrees is three o&#039;clock.]]></description>
		<content:encoded><![CDATA[<p>Zero degrees is three o&#8217;clock.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
