Skip to content

Commit a7cd3f0

Browse files
committed
Avoid unnecessary ducking
1 parent c7037ed commit a7cd3f0

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

Entities/AHuman.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,12 +1721,23 @@ void AHuman::UpdateWalkAngle(AHuman::Layer whichLayer) {
17211721

17221722
if (m_pHead) {
17231723
// Cast a ray above our head to either side to determine whether we need to crouch
1724-
float desiredCrouchHeadRoom = std::floor(m_pHead->GetRadius() + 1.5f);
1724+
float desiredCrouchHeadRoom = std::floor(m_pHead->GetRadius() + 2.0f);
17251725
float toSide = std::floor(m_pHead->GetRadius() + 3.0f);
1726-
Vector hitPosLeft = (m_pHead->GetPos() + Vector(-toSide, 0.0F)).Floor();
1727-
Vector hitPosRight = (m_pHead->GetPos() + Vector(toSide, 0.0F)).Floor();
1728-
g_SceneMan.CastStrengthRay(hitPosLeft, Vector(0.0F, -desiredCrouchHeadRoom), 10.0F, hitPosLeft, 0, g_MaterialGrass);
1729-
g_SceneMan.CastStrengthRay(hitPosRight, Vector(0.0F, -desiredCrouchHeadRoom), 10.0F, hitPosRight, 0, g_MaterialGrass);
1726+
Vector hitPosLeftStart = (m_pHead->GetPos() + Vector(-toSide, m_SpriteRadius * 0.5F)).Floor();
1727+
Vector hitPosRightStart = (m_pHead->GetPos() + Vector(toSide, m_SpriteRadius * 0.5F)).Floor();
1728+
Vector hitPosLeft, hitPosRight;
1729+
g_SceneMan.CastStrengthRay(hitPosLeftStart, Vector(0.0F, -desiredCrouchHeadRoom + m_SpriteRadius * -0.5F), 10.0F, hitPosLeft, 0, g_MaterialGrass);
1730+
g_SceneMan.CastStrengthRay(hitPosRightStart, Vector(0.0F, -desiredCrouchHeadRoom + m_SpriteRadius * -0.5F), 10.0F, hitPosRight, 0, g_MaterialGrass);
1731+
1732+
// Don't do it if we're already hitting, we're probably standing next to a wall
1733+
if (hitPosLeftStart == hitPosLeft) {
1734+
hitPosLeft.m_X = 0.0F;
1735+
}
1736+
1737+
if (hitPosRightStart == hitPosRight) {
1738+
hitPosRight.m_X = 0.0F;
1739+
}
1740+
17301741
float headroom = m_pHead->GetPos().m_Y - std::max(hitPosLeft.m_Y, hitPosRight.m_Y);
17311742
float adjust = desiredCrouchHeadRoom - headroom;
17321743
float walkPathYOffset = std::clamp(LERP(0.0F, 1.0F, -m_WalkPathOffset.m_Y, adjust, 0.3F), 0.0F, m_MaxWalkPathCrouchShift);

0 commit comments

Comments
 (0)