
Quake DeveLS - The Gunslingers Trick shot
Author: WonderSlug
Difficulty: Easy
I have been poking my way
around the q2 source and playing around implementing these great tutorials. I
was about 3/4 of the way down the list and I noticed something a little odd.
My blaster blots were not
making any sound when they ricocheted off the walls.
You have all see those
Westerns where the gunfighter shoots from the hip...off the bell in the
tower..off the whiskey bottle....off the whatever...parts the disbelievers hair
down the middle and puts a hole right through the center of the Ace of Spades.
And there is always the
sounds like phting, zhmmmmp, clank and "Damnit, that was a new deck of
cards!"
This is a quick little tutorial
which gives a little more depth to SUMFUKA's great
Bouncing Gun tutorial.
First you have to
implement the Bouncing Gun Tutorial.....go do it
now if you havent already.
Next we need to think a
little about when we are actually going to make the sound. Its not with the
gun...its when bolt hits the wall. Open up g_phys.c and goto the
SV_Physics_Toss it should be arounds line 642 with the Bouning Gun stuff
implimented.
New Variable....
First we have to add a
local variable to handle a random number...(more explanation later) Change the
Section at the top of the function from
trace_t trace; vec3_t move; float backoff; edict_t *slave; qboolean wasinwater; qboolean isinwater; vec3_t old_origin;
To this
trace_t trace; vec3_t move; float backoff; edict_t *slave; qboolean wasinwater; qboolean isinwater; vec3_t old_origin; //WonderSlug - Added for Random Ricochet Sound int rnum; //End- WonderSlug
The Sound of "Shees I better Duck!"
Next we need to add the
Sounds themselves....
Go to the section you
added to change the velocity vector...it should look like this.
// STEVE... added this part to re-align the entity's angles after // it bounces off a wall. Simply set its angles to its velocity vector. if (ent->movetype == MOVETYPE_FLYRICOCHET) { vectoangles (ent->velocity, ent->s.angles); }
Now change
it to this...
// STEVE... added this part to re-align the entity's angles after // it bounces off a wall. Simply set its angles to its velocity vector. if (ent->movetype == MOVETYPE_FLYRICOCHET) { vectoangles (ent->velocity, ent->s.angles); //WonderSlug --- Add in Ricochet Sounds rnum = rand(); //Will make a sound about 1/2 the time if (rnum < (RAND_MAX/2)){ //Pick one of three Rico Sounds if (rnum < ((RAND_MAX/2)/3)) gi.positioned_sound(old_origin, ent, CHAN_WEAPON, gi.soundindex ("world/ric1.wav"), 1, ATTN_STATIC, 0); else if (rnum < ((RAND_MAX/2)/3)*2) gi.positioned_sound(old_origin, ent, CHAN_WEAPON, gi.soundindex ("world/ric2.wav"), 1, ATTN_STATIC, 0); else gi.positioned_sound(old_origin, ent, CHAN_WEAPON, gi.soundindex ("world/ric3.wav"), 1, ATTN_STATIC, 0); } }What we are doing is
adding a ricochet sound in about half the time it hits something and were are
picking a random sound of the three ricochet sounds that come with q2. Playing
the ricochet sound every time can really run you out of space quick...if you
have something like ...say a Triple HyperBlaster for instance.
Notice we are using the
positioned_sound function with the Game Interface gi. This allows the sound to
seem like its coming from the point of impact which in this case is the
variable old_origin.
Also note we are using the
ATTN_STATIC for the attenuation. What this means is that the farther away the
bolt is when it ricochets the quieter the sound is. Its quiet for the shooter
maybe, but not for the one on the receiving end.
This is all for personal
taste of course...I just like a bit of realisim in my coding. Its also nice to
be able to hear when someone is shooting at you around the corner. :)
Have fun and Avoid the
Salt folks -=WonderSlug
Tutorial by WonderSlug
|
This site, and all content and graphics
displayed on it, |