Question about shotgun...

Discuss programming in the QuakeC language.
Post Reply
Orion
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Question about shotgun...

Post by Orion »

Hey, I just have a little curiosity on FireBullets.
I know it uses a vector to define horizontal and vertical spread, but I want to know the following: 0.1 in the vector means how many degrees of spread?
hondobondo
Posts: 207
Joined: Tue Sep 26, 2006 2:48 am
Contact:

Re: Question about shotgun...

Post by hondobondo »

Orion wrote:Hey, I just have a little curiosity on FireBullets.
I know it uses a vector to define horizontal and vertical spread, but I want to know the following: 0.1 in the vector means how many degrees of spread?
5 degrees.

haha just kidding. no idea. i usually just try numbers till i get what i want
Orion
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Post by Orion »

I think the numbers are degrees/100.

Because I tweaked FireBullets to not randomize the direction of the bullet, so I made the shotgun fire a single bullet horizontally, which I used '0.1 0 0' in the vector and set my fov to 10, and the bullet was hitting exatclty at the edge of my screen... So 0.1 is about 10 degrees. :wink:
sp4x0r
Posts: 16
Joined: Mon Jul 21, 2008 11:48 am

Post by sp4x0r »

Going verbose about this, just cos I find it useful when searching the forum to find detailed answers to other people's questions (i.e. for future readers, not just the OP):

the vector "spread" is used in FireBullets:

Code: Select all

direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
So you've got crandom() (which is a value between 1 and -1) * the spread values (which are between 0 and 1) * v_right or v_left.

So when in FireShotgun it calls:

Code: Select all

FireBullets (6, dir, '0.04 0.04 0');
(where the "'0.04, 0.04, 0'" bit is the spread vector)

you're only getting at maximum a +0.04 or -0.04 change on whatever v_right or v_up is. If crandom() happens to be 0 then the pellet will go straight on target.

[edited out the really wrong bits here - gah!]
[edit 2: didn't get it right the second time. You should ignore the rest of this post... leaving it here for evidence of my noobishness]

So the spread value isn't really a measurement in degrees, it's a proportion of whatever the vector for directly right or directly "up" is. It's been a while since I played around with v_forward or v_up, but I guess it's safe to assume they point 90 degrees away from wherever the player is facing, so

0.04 * 90 = 3.6
[Wrong!]

I could have screwed that up [edit: and I did, but then I thought about it more. edit 2: and still got it wrong]. I've been drinking. Sounds about right [now].

Anyway, if I am right then 0.1 * 90 = 9

which is obviously pretty close to the 10 degrees you're talking about.

Hey, I guess this means that the potential spread of a shotgun in Quake is a pyramid and not a cone.

I normally bite the bullet and just print all the values of what I'm interested in to the console so I can experiment and see what they hell they are, but since this is all done in vectors you won't get an angle to print unless you write some code to calculate it.
Last edited by sp4x0r on Sun Feb 06, 2011 7:16 am, edited 2 times in total.
Orion
Posts: 476
Joined: Fri Jan 12, 2007 6:32 pm
Location: Brazil

Post by Orion »

Yeah that's pretty close...
I asked this because I'm making a CTF mod with Doom weapons. And Doom Wiki says the pistol, shotguns and chaingun spreads in degrees, so I can use an equivalent value. :)
Lardarse
Posts: 266
Joined: Sat Nov 05, 2005 1:58 pm
Location: Bristol, UK

Post by Lardarse »

Since sp4x0r put all of the groundwork into getting the right answer, and then got it wrong at the end:

0.1 (or 0.04, to use the number that FireShotgun() uses) isn't directly an angle measurement at all. It's "for every unit that the pellet moves forward, it can move left or right (or up or down) by upto this amount". However, using some fairly simple trigonometry, you can convert it easily.

You have the adjacent and the opposite, so the function that you want to convert this is to an angle is atan() to get the angle, or tan() to convert the angle into a spread. Note that if you're using Google Calculator, you will have to multiply the result of atan by 180/pi to convert it from radians to degrees.

This gives us:

0.04 (Horizontal and vertical SG spread): 2.3 degrees

0.06 (LordHavoc mentioned once that this is a realistic spread for shotguns): 3.4 degrees

0.08 (Vertical SSG spread): 4.6 degrees

0.1: 5.7 degrees

0.14 (Horizontal SSG spread): 8.0 degrees

You'll note that 5.7 is fairly close to what the Doom Wiki says is the spread for 3 of the bullet weapons (the Doom SSG has a larger spread). Although 5.5 (the maximum angle of deviation, according to them) is slightly incorrect. 5.6 is closer (5.625 is exact; It's related to how the Doom engine stores angles). This means that the spread you want is 0.0985; I don't think that people will complain much if you just simplify that to '0.1 0 0'. For completeness, the Doom SSG is '0.199 0.123 0'.

Note that the pistol and chaingun, for their first shot only, fire without any spread, and thatt he chaingun will always fire an even number of bullets (assuming that there's enough ammo). And that bullets do 1d3 * 5 damage each (from players; monster bullets do a slightly different amount. The Doom Wiki implies 1d5 * 3, but I am unable to verify this). And Doom weapons use timings that are based on running at 35 FPS.

It all depends on how accurate you want to be...
Roaming status: Testing and documentation
goldenboy
Posts: 924
Joined: Fri Sep 05, 2008 11:04 pm
Location: Kiel
Contact:

Post by goldenboy »

Listen to this man.
sp4x0r
Posts: 16
Joined: Mon Jul 21, 2008 11:48 am

Post by sp4x0r »

Oh, yeah. I did get that wrong. Oops, sorry for the misdirection.

v_right + v_forward would point 45 degrees to the right of where the player is facing, not 90. And that's absolutely right about the need for trigonometry. Oh, dopey me ;-)
Post Reply