Jump to content
  • Advertisement
Sign in to follow this  
Boruki

Bullets/shots

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm curious on the best way to handle bullets/shots within a game. By this I mean bullets fired which have no actual form. Where the bullets hit instantly, ala machine gun in Quake 2. Draw a line from the character, through the heading, and see what it hits? (and add randomness as appropriate) Thanks, Bobo the Clown

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Boruki
Draw a line from the character, through the heading, and see what it hits? (and add randomness as appropriate)


Yep - thats pretty much it. Do a raycast and find the closest collision, if its a wall draw a bullet hole, if its a character calc damage. Its simple, effective and quick. You can simulate a bullet flying at huge speed but most collision detection systems can't really deal with this properly (ie bullet jumps straight through objects in one time step and misses collision) so a ray cast is really usefull. And no one will notice the difference really :P

Share this post


Link to post
Share on other sites
Just wondering if anyone could point me to a -simple- thing where I can look at this? I have a habit of making simple things 10000 times more complicated.

Thannks, Bobo

Share this post


Link to post
Share on other sites
Quote:
Original post by Boruki
Just wondering if anyone could point me to a -simple- thing where I can look at this? I have a habit of making simple things 10000 times more complicated.

Thannks, Bobo


I'd suggest the Quake 2 source code! There's one function, I can't remember exactly what it's called, but it's called by all the hitscan weapons, and called in gobs by the shotguns, and if memory serves it takes a vector, and returns a list of things that it intersected.

Share this post


Link to post
Share on other sites
This may not be too efficient, but use a loop, and see if there is a collision at a certain interval of positions.

Share this post


Link to post
Share on other sites
Quote:
Original post by Omaha
I'd suggest the Quake 2 source code! There's one function, I can't remember exactly what it's called, but it's called by all the hitscan weapons, and called in gobs by the shotguns, and if memory serves it takes a vector, and returns a list of things that it intersected.


It's normally me recommending people to look at the Quake 2 source. But I wasn't going to use that cause it's quite a complicated program. But if no-one has a better suggestion I guess I'll try that.

Share this post


Link to post
Share on other sites
notice that, but you cant use ray cast for rocket like "slow" bullets, because the geometry you are testing will be changed when it flies. you may do calculations step by step for this..

Share this post


Link to post
Share on other sites
Erm, I looked at the Quake 2 trace stuff... and it's all pretty complicated for someone who hasn't involved themselves in tracing before. I was wondering if anyone had some simple way of infinite ray tracing given an initial position and a heading? Or something? Help, please... my head is getting so croweded. Hehe.

-Bobo the Clown

Share this post


Link to post
Share on other sites
What are you using to store your scene geometry and objects? That will affect how easy/fast this step is.

For my project, I use bounding volume hierarchies for moving data, and an Axis Aligned Bounding Box Tree for the scene triangles.

It basically boils down to doing a series of ray vs aa box overlap tests on smaller and smaller boxes, until you find the exact object or triangle that the ray hits.

It's best to have two routines, one for 'shadow rays' that return as soon as anything solid is hit, and another for bullets, where you return the 1st solid object encountered, and possibly the normal at the collision point and the distance or time to that object ( in case you want to make further shots do less damage, etc. ).

The shadow rays method is used for line of sight tests for AI, and also for calculating terrain or static geometry shadows.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!