Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Gaming > Development Programming Algorithms > Re: Bullets!
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 666 of 675
Post > Topic >>

Re: Bullets!

by Miss Elaine Eos <Misc@[EMAIL PROTECTED] > Mar 24, 2008 at 02:05 AM

In article <5aaf$47e6cbe8$4f612435$5605@[EMAIL PROTECTED]
>,
 "CMulvey" <devnull@[EMAIL PROTECTED]
> wrote:
> This might sound like a very elementary question, i've been working on a
> small personal project making a top down shooting game where the player
> controls a character(sprite) using the mouse, the player's character
should
> be able to shoot from its current location, in a straight line in at the
> cursor.
> 
> The problem i'm having is that I can't seem to get the player's
character to
> shoot anywhere near the cursor and also, it won't shoot at a constant
speed,
> i've tried a couple of different approaches which each seemed to end in
> disaster. Most of the time the character can move around and do what hes
> told but when the character is instructed to shoot the bullets fly off
in
> any direction apart from the one hes supposed to be aiming at, and at
random
> speeds.
> 
> So basicly what i'm looking for is a little short algorythym to
calculate
> the coordinates for each frame when a bullet is shot from the position
of
> the players character e.g: coordinates 50,50 to where ever the cursor is
> aiming e.g (200,250) at a constant speed. The bullet terminates and is
> destroyed when it reaches the boundarys of the screen(already have this
> done).

Keep in mind that screen cordinates look like this:

-y



+y
 -x          +x

While mathematical coordinates look like this:

+y


-y
 -x          +x

Also note that 0° in math is pointing along the X axis and 90° is along 
the Y -- this is very different from the compass, where North is along 
the Y and 90° is along the X.

So you'll need a couple of routines to convert those.  qed.

The gist of getting a bullet to go at constant speed is:

* Make sure the bullet has systemTime() of last movement stored.  
(initialize this when fired.)
* At every frame...
   - Get system time
   - distance to move = (prevTime - currentTime) * speed
   - new locationX = old locationX + (cos (direction) * distance to move)
   - Similar for Y, use sin().

Remember to do the X/Y translations, and also to adjust the 
direction-fired accordingly.  Again:


Compass:

      0
      |
270 --+-- 90
      |
     180

Math functions:

     90
      |
180 --+-- 0
      |
     270

(Most math functions are in radians, also -- so you'll want to not 
forget to do THAT conversion...!)

-- 
Please take off your pants or I won't read your e-mail.
I will not, no matter how "good" the deal, patronise any business which
sends
unsolicited commercial e-mail or that advertises in discussion newsgroups.
 




 3 Posts in Topic:
Bullets!
"CMulvey" <d  2008-03-23 21:30:04 
Re: Bullets!
Miss Elaine Eos <Misc@  2008-03-24 02:05:19 
Re: Bullets!
IsaacKuo <mechdan@[EMA  2008-04-01 13:01:37 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Jul 9 4:46:20 CDT 2008.