Sign in to follow this  
ov3r_dr1v3

bullets in a 3D world

Recommended Posts

ov3r_dr1v3    122
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 this post


Link to post
Share on other sites
haegarr    7372
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 this post


Link to post
Share on other sites
settis    122
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

(Perhapes it will help you) ^^
good luck with it

Share this post


Link to post
Share on other sites
ov3r_dr1v3    122
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this