UTIL_BloodSpray

From Valve Developer Community
Jump to: navigation, search

UTIL_BloodSpray is a UTIL provided in the Source code for creating a "bloodspray" effect.

Usage

//-----------------------------------------------------------------------------
// Purpose: 
//          
// Input  : Vector - &pos | Position to create the Blood Impact at.
// Input  : Vector - &dir | Direction to create the Blood Impact in.
// Input  : int - color   | Type of blood to create. 
// Input  : int - Amount  | Amount of blood impacts to create
// Input  : int - flags   | Part of the data for DispatchEvent
// Output : 
//-----------------------------------------------------------------------------
void UTIL_BloodSpray( const Vector &pos, const Vector &dir, int color, int amount, int flags )

Flags

const int FX_BLOODSPRAY_DROPS	= 0x01;
const int FX_BLOODSPRAY_GORE	= 0x02;
const int FX_BLOODSPRAY_CLOUD	= 0x04;
const int FX_BLOODSPRAY_ALL	= 0xFF;

Examples

UTIL_BloodSpray( vecOrigin, vecDir, BLOOD_COLOR_RED, 4, FX_BLOODSPRAY_ALL );
//This example creates a blood spray from an attachment point.
//This is seen in npc_hunters.
//Line 4322 in npc_hunter.cpp for more details!

Vector vecOrigin;
Vector vecDir;

// spray blood from the attachment point
bool bGotAttachment = false;
if ( pEvent->options )
{
	QAngle angDir;
	if ( GetAttachment( pEvent->options, vecOrigin, angDir ) )
	{
		bGotAttachment = true;
		AngleVectors( angDir, &vecDir, NULL, NULL );
	}
}

// fall back to our center, tracing forward
if ( !bGotAttachment )
{	
	vecOrigin = WorldSpaceCenter();
	GetVectors( &vecDir, NULL, NULL );
}

UTIL_BloodSpray( vecOrigin, vecDir, BLOOD_COLOR_RED, 4, FX_BLOODSPRAY_ALL );

//Create some blood decals on the world infront of our blood spray
for ( int i = 0 ; i < 3 ; i++ )
{
	Vector vecTraceDir = vecDir;
	vecTraceDir.x += random->RandomFloat( -0.1, 0.1 );
	vecTraceDir.y += random->RandomFloat( -0.1, 0.1 );
	vecTraceDir.z += random->RandomFloat( -0.1, 0.1 );

	trace_t tr;
	AI_TraceLine( vecOrigin, vecOrigin + ( vecTraceDir * 192.0f ), MASK_SOLID_BRUSHONLY, this, COLLISION_GROUP_NONE, &tr );
	if ( tr.fraction != 1.0 )
	{
		UTIL_BloodDecalTrace( &tr, BLOOD_COLOR_RED );
	}
}
UTIL_BloodSpray( vecBloodPos, Vector(0,0,-1), GetEnemy()->BloodColor(), 8, FX_BLOODSPRAY_ALL );