| www.delorie.com/archives/browse.cgi | search |
| From: | Arno Fehm <afehm AT bigfoot DOT de> |
| Newsgroups: | comp.games.development.programming.algorithms,comp.os.msdos.djgpp |
| Subject: | Re: Calculating direction to shoot in |
| Date: | Sat, 01 May 1999 18:23:07 +0200 |
| Organization: | Regionales Rechenzentrum Erlangen, Germany |
| Message-ID: | <372B2A6B.E0D572D9@bigfoot.de> |
| References: | <372AFE6B DOT D048BBCE AT webmail DOT co DOT za> |
| NNTP-Posting-Host: | dial9.rz.fh-nuernberg.de |
| Mime-Version: | 1.0 |
| X-Mailer: | Mozilla 4.03 [de] (Win95; I) |
| Lines: | 35 |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
Hi you!
Ebola wrote:
> 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?
Well, two points do not really have an 'angle' (you need 3)!!! What you
probably want is the angle in relation to the x-axis.
Then it's simple vector subtraction! ( let a be the angle )
101 235 -134
Player - Enemy = direction
254 456 -202
Trigonometry tells us (sqrt(x) is the square root of x):
sin a = ( -202 ) / sqrt( (-134)² + (-202)² ) => a = -56°
cos a = ( -134 ) / sqrt( (-134)² + (-202)² )
You probably have to pay to attention if you have to add something like
180° or not!
Hope, this helps you a bit!
--
Arno Fehm (afehm AT bigfoot DOT de)
------------------------------------------------------------------------
Member of Grey Dreams Design: visit http://GreyDreams.home.pages.de !!!!
He who can destroy a thing has the real control over it. (Frank Herbert)
------------------------------------------------------------------------
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |