Skip to content
Merged
Show file tree
Hide file tree
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
28 changes: 27 additions & 1 deletion src/game/shared/neo/neo_predicted_viewmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,33 @@ void CNEOPredictedViewModel::CalcViewModelView(CBasePlayer *pOwner,
m_angOffset = angOffset;
}

newPos += vForward * vOffset.x;
constexpr int VIEWMODEL_MOVE_DISTANCE = 32; // max distance viewmodel can move is actually (1 - 0.375) * 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?
{
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 extend since not using a sphere)
UTIL_TraceHull(startPos, endPos, Vector(-4,-4,-4), Vector(4,4,4), MASK_SHOT_HULL, pOwner, COLLISION_GROUP_NONE, &tr);
tr.fraction = max(0.375, tr.fraction); // The smallest value tr.fraction can have given the size of the player hull. Stuff we want the viewmodel to react to like players don't collide with our playerhull (depending on the settings) at which point tr.fraction can be as low as 0

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;
}

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

newPos += (vForward * vOffset.x) - finalGunPush;
newPos += vRight * vOffset.y;
newPos += vUp * vOffset.z;
}
Expand Down
2 changes: 2 additions & 0 deletions src/game/shared/neo/neo_predicted_viewmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class CNEOPredictedViewModel : public CPredictedViewModel
float m_flLeanRatio;
CInterpolatedVar<float> m_iv_flLeanRatio;
#endif
float m_flGunPush = 0.f;
float m_flGunPushLastChangeTime = 0.f;

private:
float m_flStartAimingChange;
Expand Down