Ask the Guru: Response to Gravity answer from Levelord; qc mods for gravity

...I definitely agree! It is one of the cooler effects in Quake and one that is greatly under-used, me thinks. There is no low gravity trigger or entity field in standard Quake; only the level-wide gravity parameter. However, don't cha know the evil genius of Dr. Dose has added this enhancement to our Scourge of Armagon. Patience, lad, the pack is almost done ;)

- Levelord

Jim Dosé's Response:

While I'd like to take credit for this, alas, I can't. Mark did the trigger to change the gravity and John Cash added the gravity field to Quake C. Changing gravity will be an easy task in the upcoming version of Quake (v1.07).

In the meantime, however, here's how to change the player's gravity in Quake C in older versions of Quake.

PlayerPreThink in client.qc:

//--------------------------------------
// id code:
//--------------------------------------

 if (intermission_running)
 {
  IntermissionThink ();	// otherwise a button could be missed between
  return;					// the think tics
 }

 if (self.view_ofs == '0 0 0')
  return;		// intermission or finale

 makevectors (self.v_angle);		// is this still used

//--------------------------------------
// Add code to negate gravity here:
//--------------------------------------

 worldGravity = cvar("sv_gravity");
 newGravity = 100;
 self.velocity_z = self.velocity_z + (worldGravity - 
    newGravity) * frametime;

Remember to add the variable definitions at the top of the function:

local float worldGravity;
local float newGravity;

The code is pretty self explanatory. We simply add the current gravity level back into the player's velocity and subtract the new gravity. With some changes, you could give each character different levels of gravity when he touches a trigger.

If you want some real fun, treat the new gravity like a vector and you can have gravity pull you in any direction:

local vector newGravity;

newGravity = '800 0 0';
if ( !( self.flags & FL_ONGROUND ) )
   {
   self.velocity = self.velocity - newGravity * frametime;
   }

This bit of code causes you to fly westward when you jump or fall. This is neat, but probably impractical unless it's triggered on and off.

- Jim Dosé

The Forge: The Official Worldcraft Editing Site - ©1997