Skip to content

Commit ab0011e

Browse files
committed
Don't angle when up against a wall
1 parent 23b88ae commit ab0011e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Source/Entities/AHuman.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,14 +1356,23 @@ void AHuman::UpdateWalkAngle(AHuman::Layer whichLayer) {
13561356

13571357
// Cast a ray down from the left and right of us, to determine our angle of ascent
13581358
// TODO Don't use a magic number here, calculate something based on stride length and maybe footgroup width.
1359-
Vector hitPosLeft = hipPos + Vector(-10.0F, 0.0F);
1360-
Vector hitPosRight = hipPos + Vector(10.0F, 0.0F);
1361-
g_SceneMan.CastStrengthRay(hitPosLeft, Vector(0.0F, rayLength), 10.0F, hitPosLeft, 0, g_MaterialGrass);
1362-
g_SceneMan.CastStrengthRay(hitPosRight, Vector(0.0F, rayLength), 10.0F, hitPosRight, 0, g_MaterialGrass);
1359+
Vector startPosLeft = hipPos + Vector(-10.0F, 0.0F);
1360+
Vector startPosRight = hipPos + Vector(10.0F, 0.0F);
1361+
Vector hitPosLeft, hitPosRight;
1362+
g_SceneMan.CastStrengthRay(startPosLeft, Vector(0.0F, rayLength), 10.0F, hitPosLeft, 0, g_MaterialGrass);
1363+
g_SceneMan.CastStrengthRay(startPosRight, Vector(0.0F, rayLength), 10.0F, hitPosRight, 0, g_MaterialGrass);
1364+
1365+
float angle = 0.0F;
1366+
1367+
// If we immediately hit something, we're probably against a wall. So don't bother trying to walk over it
1368+
bool immediateHit = hitPosLeft == startPosLeft || hitPosRight == startPosRight;
1369+
if (!immediateHit) {
1370+
angle = (hitPosRight - hitPosLeft).GetAbsDegAngle();
1371+
}
13631372

13641373
// Clamp the max angle, so we don't end up trying to walk at a 80 degree angle up sheer walls
13651374
const float maxAngleDegrees = 40.0F;
1366-
float terrainRotationDegs = std::clamp((hitPosRight - hitPosLeft).GetAbsDegAngle(), -maxAngleDegrees, maxAngleDegrees);
1375+
float terrainRotationDegs = std::clamp(angle, -maxAngleDegrees, maxAngleDegrees);
13671376

13681377
//const float fastMovementAngleReduction = 10.0F;
13691378
//const float ourMaxMovementSpeed = std::max(m_Paths[FGROUND][WALK].GetSpeed(), m_Paths[BGROUND][WALK].GetSpeed()) * 0.5F;

0 commit comments

Comments
 (0)