Mail Archives: djgpp/1999/05/01/23:06:35
From: | "Christopher Nelson" <paradox AT gye DOT satnet DOT net>
|
To: | <djgpp AT delorie DOT com>
|
Subject: | Re: Calculating direction to shoot in
|
Date: | Sat, 1 May 1999 20:27:53 -0600
|
Message-ID: | <01be9443$61ce9200$LocalHost@thendren>
|
MIME-Version: | 1.0
|
X-Priority: | 3
|
X-MSMail-Priority: | Normal
|
X-Mailer: | Microsoft Outlook Express 4.71.1712.3
|
X-MimeOLE: | Produced By Microsoft MimeOLE V4.71.1712.3
|
Reply-To: | djgpp AT delorie DOT com
|
>I am programming a 2d space game. The game is seen from aboce and the
>player can rotate his ship so that he can travel in any direction, not
>just up, down, left and right. The problem is: How do I calculate the
>direction/angle the computer controlled enemies have to shoot in to hit
>the player? For example: The player is at coordinates (101, 254) and the
>enemy is at (235, 456). How can I calculate the angle between them?
if i remember correctly, you should be able to take the arctangent of the
slope between the two vectors, and that will give your angle.
e.g. angle = arctan((456-254)/(235-101));
in other words, the angle is equal to the arc tangent of the slope.
slope = rise / run
rise = (253-101);
run = (456-254);
it's something like this anyway. :-)
-={C}=-
- Raw text -