Thread: "Gun" bullets moving around?

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

    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?


    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
    Plano, Texas, United States
    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 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 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
    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
    >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
    Buffalo, NY
    1,033 this physics? am I gunna have to learn this when i do 3d games?

  6. #6
    Originally posted by Xterria this physics? am I gunna have to learn this when i do 3d games?
    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-23-2007, 11:05 PM
  2. moving median function
    By supermeew in forum C Programming
    Replies: 0
    Last Post: 05-04-2006, 02: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, 08:31 PM
  5. pic movement
    By pode in forum Game Programming
    Replies: 31
    Last Post: 08-21-2002, 09:30 PM