From: Unigni Newsgroups: comp.games.development.programming.algorithms,comp.os.msdos.djgpp Subject: Re: Calculating direction to shoot in Date: Sat, 1 May 1999 16:59:56 +0100 Organization: Zaynar Productions Distribution: world Message-ID: References: <372AFE6B DOT D048BBCE AT webmail DOT co DOT za> NNTP-Posting-Host: zaynar.demon.co.uk X-NNTP-Posting-Host: zaynar.demon.co.uk:158.152.90.16 X-Trace: news.demon.co.uk 925575926 nnrp-10:7941 NO-IDENT zaynar.demon.co.uk:158.152.90.16 X-Complaints-To: abuse AT demon DOT net MIME-Version: 1.0 X-Newsreader: Turnpike Version 3.03a Lines: 20 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com In article <372AFE6B DOT D048BBCE AT webmail DOT co DOT za>, Ebola writes >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? The code used in QBasic is: Angle = ATN((x2 - x1) / (y2 - y1)) where x1,y1 would be the co-ordinates of the enemy ship, and x2,y2 would be the target. ATN returns the 'arc tangent' (the angle -- in QB it's in radians; I'm not sure about other languages...) -- Philip Taylor philip @ zaynar . demon . co . uk http://www.zaynar.demon.co.uk/atr - Programming robots!