Here is the code taken from Half Life 2:
This is the original unmodified code, I've made an attempt at converting it from C++ to UScript before and I was unsuccessful. Can somebody help me out?
Code:
#define MAX_VIEWMODEL_LAG 1.5f
void CBaseViewModel::CalcViewModelLag( Vector& origin, QAngle& angles, QAngle& original_angles )
{
// Calculate our drift
Vector forward;
AngleVectors( angles, &forward, NULL, NULL );
if ( gpGlobals->frametime != 0.0f )
{
Vector vDifference;
VectorSubtract( forward, m_vecLastFacing, vDifference );
if ( fabs( vDifference.x ) > MAX_VIEWMODEL_LAG ||
fabs( vDifference.y ) > MAX_VIEWMODEL_LAG ||
fabs( vDifference.z ) > MAX_VIEWMODEL_LAG )
{
m_vecLastFacing = forward;
}
// FIXME: Needs to be predictable?
VectorMA( m_vecLastFacing, 5.0f * gpGlobals->frametime, vDifference, m_vecLastFacing );
// Make sure it doesn't grow out of control!!!
VectorNormalize( m_vecLastFacing );
VectorMA( origin, 5, vDifference * -1, origin );
}
Vector right, up;
AngleVectors( original_angles, &forward, &right, &up );
float pitch = original_angles[ PITCH ];
if ( pitch > 180.0f )
pitch -= 360.0f;
else if ( pitch < -180.0f )
pitch += 360.0f;
//FIXME: These are the old settings that caused too many exposed polys on some models
VectorMA( origin, -pitch * 0.035f, forward, origin );
VectorMA( origin, -pitch * 0.03f, right, origin );
VectorMA( origin, -pitch * 0.02f, up, origin);
}
This is the original unmodified code, I've made an attempt at converting it from C++ to UScript before and I was unsuccessful. Can somebody help me out?