Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 36 additions & 23 deletions src/game/shared/neo/neo_predicted_viewmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,12 @@ float CNEOPredictedViewModel::lean(CNEO_Player *player){
return -m_flLeanRatio * ((player->GetClass() == NEO_CLASS_JUGGERNAUT) ? 20.0f : neo_lean_tp_angle.GetFloat());
}

#ifdef CLIENT_DLL
static constexpr int HALF_HULL_SIZE = 12; // is this defined globally somewhere?
ConVar cl_neo_viewmodel_bump("cl_neo_viewmodel_bump", "1", FCVAR_ARCHIVE, "Bump viewmodel against solids", true, 0, true, 1);
ConVar cl_neo_viewmodel_bump_amount("cl_neo_viewmodel_bump_amount", "24", FCVAR_ARCHIVE, "How far back to bump the viewmodel", true, HALF_HULL_SIZE, true, 36);
#endif

extern ConVar cl_righthand;
void CNEOPredictedViewModel::CalcViewModelView(CBasePlayer *pOwner,
const Vector& eyePosition, const QAngle& eyeAngles)
Expand Down Expand Up @@ -550,35 +556,42 @@ void CNEOPredictedViewModel::CalcViewModelView(CBasePlayer *pOwner,
m_angOffset = angOffset;
}

constexpr int VIEWMODEL_MOVE_DISTANCE = 24; // max distance viewmodel can move is actually VIEWMODEL_MOVE_DISTANCE - HALF_HULL_SIZE
constexpr int HALF_HULL_SIZE = 12; // is this defined globally somewhere?
constexpr float VIEWMODEL_MOVE_FRACTION_MIN = (VIEWMODEL_MOVE_DISTANCE - HALF_HULL_SIZE) / VIEWMODEL_MOVE_DISTANCE;
if (m_flGunPushLastChangeTime < gpGlobals->curtime) // Why is this value sometimes greater than current time? Also this fixes gun moving back much slower around some corners, maybe weird prediction stuff?
#ifdef CLIENT_DLL
Vector finalGunPush = vec3_origin;
if (cl_neo_viewmodel_bump.GetBool())
{
constexpr float MAX_GUN_PUSH_FRACTION_CHANGE_PER_SECOND = 2.5f;
float maxFractionChange = (gpGlobals->curtime - m_flGunPushLastChangeTime) * MAX_GUN_PUSH_FRACTION_CHANGE_PER_SECOND;
m_flGunPushLastChangeTime = gpGlobals->curtime;

trace_t tr;
Vector startPos = pOwner->EyePosition();
Vector endPos = pOwner->EyePosition() + (vForward * VIEWMODEL_MOVE_DISTANCE);
// NEO NOTE (Adam) the hull generated by tracehull is fixed to the axis, using a non square cube shape will give varying results depending on player orientation to the obstacle in front of them (already the case to an extent since not using a sphere)
UTIL_TraceHull(startPos, endPos, Vector(-4,-4,-4), Vector(4,4,4), MASK_SOLID &~ CONTENTS_MONSTER, pOwner, COLLISION_GROUP_NONE, &tr);
tr.fraction = Max(VIEWMODEL_MOVE_FRACTION_MIN, tr.fraction); // The smallest value tr.fraction can have given the size of the player hull

if (abs(tr.fraction - m_flGunPush) < (maxFractionChange + 0.01)) // float math, don't want the gun to move when in its resting position
const int VIEWMODEL_MOVE_DISTANCE = cl_neo_viewmodel_bump_amount.GetInt(); // max distance viewmodel can move is actually VIEWMODEL_MOVE_DISTANCE - HALF_HULL_SIZE
const float VIEWMODEL_MOVE_FRACTION_MIN = (VIEWMODEL_MOVE_DISTANCE - HALF_HULL_SIZE) / VIEWMODEL_MOVE_DISTANCE;
if (m_flGunPushLastChangeTime < gpGlobals->curtime) // Why is this value sometimes greater than current time? Also this fixes gun moving back much slower around some corners, maybe weird prediction stuff?
{
m_flGunPush = tr.fraction;
}
else
{
m_flGunPush += tr.fraction > m_flGunPush ? maxFractionChange : -maxFractionChange;
}
constexpr float MAX_GUN_PUSH_FRACTION_CHANGE_PER_SECOND = 2.5f;
float maxFractionChange = (gpGlobals->curtime - m_flGunPushLastChangeTime) * MAX_GUN_PUSH_FRACTION_CHANGE_PER_SECOND;
m_flGunPushLastChangeTime = gpGlobals->curtime;

trace_t tr;
Vector startPos = pOwner->EyePosition();
Vector endPos = pOwner->EyePosition() + (vForward * VIEWMODEL_MOVE_DISTANCE);
// NEO NOTE (Adam) the hull generated by tracehull is fixed to the axis, using a non square cube shape will give varying results depending on player orientation to the obstacle in front of them (already the case to an extent since not using a sphere)
UTIL_TraceHull(startPos, endPos, Vector(-4, -4, -4), Vector(4, 4, 4), MASK_SOLID & ~CONTENTS_MONSTER, pOwner, COLLISION_GROUP_NONE, &tr);
tr.fraction = Max(VIEWMODEL_MOVE_FRACTION_MIN, tr.fraction); // The smallest value tr.fraction can have given the size of the player hull

if (abs(tr.fraction - m_flGunPush) < (maxFractionChange + 0.01)) // float math, don't want the gun to move when in its resting position
{
m_flGunPush = tr.fraction;
}
else
{
m_flGunPush += tr.fraction > m_flGunPush ? maxFractionChange : -maxFractionChange;
}

}
finalGunPush = vForward * ((1 - m_flGunPush) * VIEWMODEL_MOVE_DISTANCE);
}
Vector finalGunPush = vForward * ((1 - m_flGunPush) * VIEWMODEL_MOVE_DISTANCE);

newPos += (vForward * vOffset.x) - finalGunPush;
#else
newPos += vForward * vOffset.x;
#endif
newPos += vRight * vOffset.y;
newPos += vUp * vOffset.z;
}
Expand Down