# Drawing and calculating bullets in FPS

This topic is 4332 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi everyone, I'm making a simple FPS game and I need little help :) I have a weapon which doesn't fire. I need to create bullets but I don't know how. Are there any tips, articles or tutorials about creating and firing sprites out of the weapon and rendering them? All I need is when pressing fire button a single shot to come from the weapon toward the center of the crosshair, and when it reaches a wall or smth. like that to split in 4-5 parts and disappear. Hope you understand me. Thanks in advance.

##### Share on other sites
I don't think that this is an OpenGL Problem,

I think drawing a single Bullet is not needed, 'cause its much to fast to be seen by the eye.
You should just compute the path of your bullet (as a ray), compute where it hits anything and start a little particle effect at the hitpoint.
If you want to draw the path of the bullet you could draw it as a line (like a glowing bullet-trace).

##### Share on other sites
Use a particle system.
Try my game at:
my game
You can see sparks when you press fire.
I do about 200 particles for each fire bullet.
Also you can see bullets flying off (a bit too slowly though).
I do the bullets as very small cylinders (using quadrics).
eg suppose I'm facing in the normalised direction (vx, vy, vz) then I create a bullet with vector velocity:
BULLET_MAGNITUDE*(vx, vy, vz)

Then each frame calc deltaTime since last frame so we can get new position

bulletpos += bulletpos + velocity*deltaTime

Then draw the bullet.

glPushMatrix
glTranslatef(bulletpos.x, bulletpos.y, bulletpos.z)
glPopMatrix

(try different values of magnitude - hint - bullets go at 500m/s but you won't be able to see them at that speed)

For the particle system for an intro go to:
nehe particle sys
second example from the end
Also the book on "Focus on 3D Terrain Programming" has a good example as does the book "Game Programming with OpenGL"

I deserve to be rated up a lot for this ! hint hint

##### Share on other sites
Thanks, rated up both of you ;)

1. 1
2. 2
3. 3
4. 4
Rutin
13
5. 5

• 14
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633692
• Total Posts
3013356
×