Bouncing Rails Feature Type: Coding Tutorials     Added: 14/02  
  Author: !LuCiFeR! & Graser 

Simply bouncing rails, curtesty of !LuCiFeR! and grazer.

Code to be Deleted or Commented out
Code to be Added or Changed


All modifications will be done in g_weapon.c
Open it up and go down to weapon_railgun_fire and add this before the void:

#define MAX_RAIL_BOUNCE 4 //Luc: Defines the maximum number of bounces
void weapon_railgun_fire (gentity_t *ent) {

Then we add an integer to count our bounces like so...

int passent;
int bounce; //Luc: Bounce count
gentity_t *unlinkedEntities[MAX_RAIL_HITS];

And we gotta set it to 0...

// trace only against the solids, so the railgun will go through people
bounce = 0; //Luc: start off with no bounces
unlinked = 0;
hits = 0;
passent = ent->s.number;

And now the fun part... below the passent = ent->s.number; add:

do {
if (bounce) {
G_BounceProjectile( muzzle , trace.endpos , trace.plane.normal, end); //This sets the new angles for the bounce
VectorCopy (trace.endpos , muzzle); //copy the end position as the new muzzle

do {
trap_Trace (&trace, muzzle, NULL, NULL, end, passent, MASK_SHOT );
if ( trace.entityNum >= ENTITYNUM_MAX_NORMAL ) {

And at the end....

ent->client->ps.eFlags |= EF_AWARD_IMPRESSIVE;
ent->client->rewardTime = level.time + REWARD_SPRITE_TIME;
//Luc: Add a bounce, so it'll bounce only 4 times

} while (bounce <= MAX_RAIL_BOUNCE);

That'll make it bounce properly, but, before we finish it off, we gotta make sure that the rails dont bounce off the sky... go back up a little and do this:

if ( trace.surfaceFlags & SURF_NOIMPACT ) {
bounce = MAX_RAIL_BOUNCE; //Luc: If hit sky, max out bounces so wont bounce again
tent->s.eventParm = 255; // don't make the explosion at the end
} else {
tent->s.eventParm = DirToByte( trace.plane.normal );

There you have it, simple bouncing railguns. If you use this in your mod, please give credit where credit is due

Comments »

  Page 1

  Comments ( 0 )

  Features Index


Copyright 2001 MGON International AB - Privacy statement