UTIL_ScreenShake

From Valve Developer Community
Jump to: navigation, search

UTIL_ScreenShake is a UTIL provided in the Source code for shaking the player's screen, or controller.


Note.pngNote:UTIL_ScreenShake has a maximum amplitude of 16.0.

Usage

//-----------------------------------------------------------------------------
// Purpose: Shake the screen of all clients within radius.
//			radius == 0, shake all clients
// 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_ScreenShake( const Vector &center, 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

UTIL_ScreenShake( GetAbsOrigin(), 25.0, 150.0, 1.0, 750, SHAKE_START );
//This example takes the player, punches his view
//pushes him back, and then shakes his screen while
//making it red. It's from NPC_Hunter::MeleeAttack
if ( pPlayer != NULL && !(pPlayer->GetFlags() & FL_GODMODE ) )
{
	pPlayer->ViewPunch( qaViewPunch );
	pPlayer->VelocityPunch( vecVelocityPunch );
	
	// Shake the screen
	UTIL_ScreenShake( pPlayer->GetAbsOrigin(), 100.0, 1.5, 1.0, 2, SHAKE_START );

	// Red damage indicator
	color32 red = { 128, 0, 0, 128 };
	UTIL_ScreenFade( pPlayer, red, 1.0f, 0.1f, FFADE_IN );
}