"Gun" bullets moving around?

This is a discussion on "Gun" bullets moving around? within the Game Programming forums, part of the General Programming Boards category; With the current game I am working on, it's my first, I will need "guns". I know how to detect ...

  1. #1
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question "Gun" bullets moving around?

    With the current game I am working on, it's my first, I will need "guns". I know how to detect the key, but how do I use a function something like:

    void fire(GLvoid)
    {
    // I need this
    }

    To create a "bullet" and make it travel through the space along the y axis?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: trifaze_mattu@lycos.com

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    well...this requires basic physics.


    Position = BeginningPos + (InitialVelocity)(Time) + (1/2)(Acceleration)(Time)^2

    Now, your bullet will have to go along both the x and y axis, unless you are making a 3d game, then it will be x, y, and z axi (i wonder...is axi the plural of axis? anyways, btw).

    So you would use this equation for all the axi (assuming axi is plural for axis )

    so to figure out the y position of the bullet:

    y = BeginningY + (InitialVelocity)(Time) + (1/2)(Acceleration)(Time)^2

    BeginningY = starting y coord
    InitialVelocity = in meters/sec...probably around 300 m/s for a bullet...maybe even up to 600 m/s
    Time = amount of time since bullet was fired
    Acceleration = for the y coordinate, this would most likely be the gravitational pull...so this would be -9.8

    you would use this same equation for the x and z axi.
    Only the acceleration variable for those axi would be different. For the x axis it might be windspeed...who knows...there might not even be any acceleration.

    Also, you will need to be able to fire your bullet at different angles. Those equations I just stated assume a 90 deg. angle perpendicular to the ground. For diff. angles, do this (for the y axis):

    y = BeginningY + (InitialVelocity)(Time)(sin Angle) + (1/2)(Acceleration)(Time)^2

    for x axis:

    x = BegX + (InitialVelocity)(Time)(cos Angle) + (1/2)(Acceleration)(Time)^2

    for z:

    z = BegZ + (InitialVelocity)(Time)(tan Angle) + (1/2)(Acceleration)(Time)^2
    My Website

    "Circular logic is good because it is."

  3. #3
    Registered User johnnie2's Avatar
    Join Date
    Aug 2001
    Posts
    186
    The plural of axis is actually axes (with a long e sound), but that's so plain that I'd go ahead and use axi.
    "Optimal decisions, once made, do not need to be changed." - Robert Sedgewick, Algorithms in C

  4. #4
    Linguistic Engineer... doubleanti's Avatar
    Join Date
    Aug 2001
    Location
    CA
    Posts
    2,459
    >your bullet will have to go along both the x and y axis

    in a right-handed setup the component of acceleration would be the z axis, where x and y would ideally not vary [remember, physics is based on simple models to explain observed phenomenon]. any external forces on the system would cause changes in all three axes.
    hasafraggin shizigishin oppashigger...

  5. #5
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    uhh....is this physics? am I gunna have to learn this when i do 3d games?
    pant....pant...

  6. #6
    Unregistered
    Guest
    Originally posted by Xterria
    uhh....is this physics? am I gunna have to learn this when i do 3d games?
    pant....pant...
    elementery physics is used in games such as pong...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Moving Average Question
    By GCNDoug in forum C Programming
    Replies: 4
    Last Post: 04-24-2007, 12:05 AM
  2. moving median function
    By supermeew in forum C Programming
    Replies: 0
    Last Post: 05-04-2006, 03:37 PM
  3. 3D moving
    By bluehead in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2005, 05:46 AM
  4. bouncing bullets
    By dydoko in forum Game Programming
    Replies: 8
    Last Post: 09-18-2003, 09:31 PM
  5. pic movement
    By pode in forum Game Programming
    Replies: 31
    Last Post: 08-21-2002, 10:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21