Path: chuka.playstation.co.uk!news From: "Rad" Newsgroups: scee.yaroze.programming.2d_graphics Subject: Re: What do'you mean I have to brush up on me maths! Date: Sat, 3 Jul 1999 13:01:40 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 33 Message-ID: <7lkucs$ko217@chuka.playstation.co.uk> References: <7ko1jf$33u25@chuka.playstation.co.uk> <376fbd21.251404588@news.scea.sony.com> NNTP-Posting-Host: modem-125.name41.dialup.pol.co.uk X-Newsreader: Microsoft Outlook Express 4.72.3110.5 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Scott Cartier wrote in message <376fbd21.251404588@news.scea.sony.com>... > >You know the enemy location and the player location so you can use >those two pairs of X,Y coordinates to form a vector. Convert the >vector to a unit vector so the distance doesn't affect the speed of >the bullet. Then each frame you add this vector to the current bullet >position to make it move. Multiply each component of the unit vector >by some value to make the bullet go faster/slower. > >Take note. Unless your bullet is moving very quickly, you'll need to >make sure you have enough precision in your X,Y to avoid cumulative >rounding errors. > >For instance, if your bullet vector turns out to be dX=4.1 dY=3.9 >(43.6 degrees) then when you add this to your sprite location it will >only add the decimal part dX=4 dY=3 (36.9 degrees). A noticable >difference. Hi Scott, Ok, could you explain this with some example code or formula. I need to work out dx and dy when I know x1, y1, x2 and y2. It doesn't have to be super accurate, as long as the bullet travels roughly in the right direction. Thanks, Rad. rad@cyberdude.com http://www.netyaroze-europe.com/~radpsx