Bullets/shots

Started by
9 comments, last by helix 18 years, 10 months ago
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
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
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
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.
This may not be too efficient, but use a loop, and see if there is a collision at a certain interval of positions.
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
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.
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..
+-+-+-+-+-STR
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
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.

how do you go about clipping the decals against the geometry?
http://www.8ung.at/basiror/theironcross.html

This topic is closed to new replies.

Advertisement