# Thread: "Gun" bullets moving around?

1. ## "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?

2. 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

3. 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.

4. >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.

5. uhh....is this physics? am I gunna have to learn this when i do 3d games?
pant....pant...

6. 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...