UTIL_ScreenShakeObject
UTIL_ScreenShakeObject is a UTIL provided in the Source code for shaking objects. It will also shake all players on, or near it.
Usage
//-----------------------------------------------------------------------------
// Purpose: Shake the screen of all clients within radius.
// radius == 0, shake all clients
// Input : pEnt - Entity to shake
// Input : center - Center of screen shake, radius is measured from here.
// amplitude - Amplitude of shake
// frequency -
// duration - duration of shake in seconds.
// radius - Radius of effect, 0 shakes all clients.
// command - One of the following values:
// SHAKE_START - starts the screen shake for all players within the radius
// SHAKE_STOP - stops the screen shake for all players within the radius
// SHAKE_AMPLITUDE - modifies the amplitude of the screen shake
// for all players within the radius
// SHAKE_FREQUENCY - modifies the frequency of the screen shake
// for all players within the radius
// //OTHERS MAY APPLY (See ShakeCommand_t values below)
// bAirShake - if this is false, then it will only shake players standing on the ground.
//-----------------------------------------------------------------------------
void UTIL_ScreenShakeObject( CBaseEntity *pEnt, const Vector ¢er, float amplitude,
float frequency, float duration, float radius, ShakeCommand_t eCommand, bool bAirShake )
ShakeCommand_t values
SHAKE_START = 0, // Starts the screen shake for all players within the radius.
SHAKE_STOP, // Stops the screen shake for all players within the radius.
SHAKE_AMPLITUDE, // Modifies the amplitude of an active screen shake for all players within the radius.
SHAKE_FREQUENCY, // Modifies the frequency of an active screen shake for all players within the radius.
SHAKE_START_RUMBLEONLY, // Starts a shake effect that only rumbles the controller, no screen effect.
SHAKE_START_NORUMBLE, // Starts a shake that does NOT rumble the controller.
Examples
//This example checks if it's time to 'shake' the gun on the Airboat again
//And if so, shakes the entire airboat, like the gun was causing
//the frame to take forces from firing.
if ( gpGlobals->curtime >= m_flNextGunShakeTime )
{
//WorldSpaceCenter() gets the center of the object.
UTIL_ScreenShakeObject( this, WorldSpaceCenter(), 0.2, 250.0, CANNON_SHAKE_INTERVAL, 250, SHAKE_START );
m_flNextGunShakeTime = gpGlobals->curtime + 0.5 * CANNON_SHAKE_INTERVAL;
}