www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/05/03/17:38:14

From: "Charles Wood" <c DOT dot DOT r DOT dot DOT wood AT worldnet DOT att DOT net>
Newsgroups: comp.games.development.programming.algorithms,comp.os.msdos.djgpp
Subject: Re: Calculating direction to shoot in
Date: Mon, 3 May 1999 14:14:42 -0700
Organization: AT&T WorldNet Services
Lines: 44
Message-ID: <7gl3l4$fmf$1@bgtnsc03.worldnet.att.net>
References: <372AFE6B DOT D048BBCE AT webmail DOT co DOT za>
NNTP-Posting-Host: 12.64.37.168
X-Trace: bgtnsc03.worldnet.att.net 925766116 16079 12.64.37.168 (3 May 1999 21:15:16 GMT)
X-Complaints-To: abuse AT worldnet DOT att DOT net
NNTP-Posting-Date: 3 May 1999 21:15:16 GMT
X-Newsreader: Microsoft Outlook Express 4.72.2106.4
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

You can do it any of the ways described above, but I recommend a litle
different approach if your program stores the character vx and vy along with
x and y.


    get the delta-X and Y, then figure out how fast your missle goes, ie max
of 2 pixels per something or another.   Then divide out dx and dy by the
same number such that vx*vx+vy*vy) ^(1/2) = max_missile speed.

    On other thing to take into consideration is the relative speed of the
shooter and the reciever.  It makes those kinda games funny.  Make sure your
scheme isn't so accurate that it never misses! (i did one like this)

    The approaching missile took into account my direction. speed and
current accerelation.  Damn things were accurate!   I eventually had to add
a little randomness in the shots to make it playable.

    targetx = targetx + rand()%40 - 20;
    targety = targety + rand()%40 - 20;

    Helped out quite a bit..

BTW a physics professor gave me the formulas for the accerlation + velocity
+ position.  It's like a full page of small writing doing the solve on the
equation...

Have a good one.

Charles Wood
REMOVEMEc DOT r DOT wood AT worldnet DOT att DOT net


Ebola wrote in message <372AFE6B DOT D048BBCE AT webmail DOT co DOT za>...
>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?
>
>
>


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019