# bullets in a 3D world

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

## Recommended Posts

Hey, I'm currently having trouble with implementing shooting bullets in a 3D environment. Not even too sure how to approach this...and am struggling to find any resources on the internet to help. If anyone has any idea how to implement this i would be grateful if you could explain how to do this, likewise any links you know of that you think might be useful i would really appreciate. The approach I have took so far is to create a new bullet( basically an opengl line) and set its initial position to the current position of the camera. However, I'm not too sure how to calculate where the bullets should be fired to(described by the cross hair in the middle of the screen) I would appreciate any help anyone can provide Thanks in advance

##### Share on other sites
The bullet, if fired from the camera position to the cross hair centered on the screen, goes along a straight line. (Okay, in practice it wuold be a ballistic curve instead of a straight line, but that can be negelected in your case, I assume.) The line runs along the view direction of the camera. So its track is given by
P(t) := P0 + v * t * d
where P0 is the bullet's position when the firearms get fired (i.e. the camera position), v is the bullets speed, t is the elapsed time since firing, and d is the view direction.

Now you must define what you want to do with that knowledge. Drawing a line along the track means to not simulate a position in dependence of time. Instead you would choose an elongation f that reaches wide enough for your purposes, and yield in
P(f) := P0 + f * d
drawing a line from
P(0) == P0
up to
P(f)

The same would be useful for collision (hit) detection, since a bullet is normally so fast that simulating in discrete time steps would probably either pass the target or require too much computations.

However, you would not see any senseful on the screen, since you've chosen the camera position as P0. So both the beginning as well as the end of the line would yield in the same screen point after projection. It would hence be better to choose a starting location slighly aside and perhaps below the camera's position.

##### Share on other sites
i am also working on a game. well i wanted to know
how far i could get (at the moment it doesn`t look
very good ;) )

but here i found a source code of a FPS

http://www.gldomain.com/Programs/FirstPersonShooter.htm

good luck with it

##### Share on other sites
hey thanks for your replies...unfortunately i still can't manage to get the bullets to work properly...haegarr I didn't really understand how to implement it the way you described, would you mind explaining again, or maybe directing me somewhere to research more

I'd appreciate any help thanks

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631706
• Total Posts
3001833
×