Skip to content

Commit c031177

Browse files
committed
Made crouch detection a bit more accurate and nicer
1 parent c003b2c commit c031177

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

Entities/AHuman.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,23 +1722,23 @@ void AHuman::UpdateWalkAngle(AHuman::Layer whichLayer) {
17221722
if (m_pHead) {
17231723
// Cast a ray above our head to either side to determine whether we need to crouch
17241724
float desiredCrouchHeadRoom = std::floor(m_pHead->GetRadius() + 2.0f);
1725-
float toSide = std::floor(m_pHead->GetRadius() + 3.0f);
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);
1725+
float toPredicted = std::floor(m_Vel.m_X * m_pHead->GetRadius()); // Check where we'll be a second from now
1726+
Vector hitPosStart = (m_pHead->GetPos() + Vector(0.0F, m_SpriteRadius * 0.5F)).Floor();
1727+
Vector hitPosPredictedStart = (m_pHead->GetPos() + Vector(toPredicted, m_SpriteRadius * 0.5F)).Floor();
1728+
Vector hitPos, hitPosPredicted;
1729+
g_SceneMan.CastStrengthRay(hitPosStart, Vector(0.0F, -desiredCrouchHeadRoom + m_SpriteRadius * -0.5F), 10.0F, hitPos, 0, g_MaterialGrass);
1730+
g_SceneMan.CastStrengthRay(hitPosPredictedStart, Vector(0.0F, -desiredCrouchHeadRoom + m_SpriteRadius * -0.5F), 10.0F, hitPosPredicted, 0, g_MaterialGrass);
17311731

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;
1732+
// Don't do it if we're already hitting, we're probably in a weird spot
1733+
if (hitPosStart == hitPos) {
1734+
hitPos.m_X = 0.0F;
17351735
}
17361736

1737-
if (hitPosRightStart == hitPosRight) {
1738-
hitPosRight.m_X = 0.0F;
1737+
if (hitPosPredictedStart == hitPosPredicted) {
1738+
hitPosPredicted.m_X = 0.0F;
17391739
}
17401740

1741-
float headroom = m_pHead->GetPos().m_Y - std::max(hitPosLeft.m_Y, hitPosRight.m_Y);
1741+
float headroom = m_pHead->GetPos().m_Y - std::max(hitPos.m_Y, hitPosPredicted.m_Y);
17421742
float adjust = desiredCrouchHeadRoom - headroom;
17431743
float walkPathYOffset = std::clamp(LERP(0.0F, 1.0F, -m_WalkPathOffset.m_Y, adjust, 0.3F), 0.0F, m_MaxWalkPathCrouchShift);
17441744
m_WalkPathOffset.m_Y = -walkPathYOffset;

0 commit comments

Comments
 (0)