UTIL_Approach

From Valve Developer Community
Jump to: navigation, search

UTIL_Approach is a UTIL provided in the Source code for 'approaching' a target value. It is useful for creating non-linear movement when turning.

To do: Verify this!

Usage

//-----------------------------------------------------------------------------
// Purpose: 
//          
// Input  : target - Target value to reach
// Input  : value - Current value
// Input  : speed - Speed at which to approach the target value
// Output : float - Current value? //TODO: Check
//-----------------------------------------------------------------------------
inline float UTIL_Approach( float target, float value, float speed )
{
	return Approach( target, value, speed );
}


Examples

m_flTurn = UTIL_Approach( m_flMaxTurnSpeed, m_flTurn, flTurnAdd * gpGlobals->frametime );
SetLocalAngularVelocity( QAngle(0,m_flTurn * 10,0) );
//Gently flatten out the pitch from the starting pitch/yaw
m_existPitch = UTIL_Approach( 0.0, m_existPitch, 1 );
QAngle angles = GetLocalAngles();
angles.x = m_existPitch + ( sin( gpGlobals->curtime * 3.5f ) * DROPSHIP_MAX_LAND_TILT );
//Approach 'zero' or neutral on a PoseParameter.
//SetPoseParameter takes PoseParameter, and the value to be at.
SetPoseParameter( m_poseHead_Yaw, UTIL_Approach( 0, yaw, 10 ) );