@@ -1356,14 +1356,23 @@ void AHuman::UpdateWalkAngle(AHuman::Layer whichLayer) {
1356
1356
1357
1357
// Cast a ray down from the left and right of us, to determine our angle of ascent
1358
1358
// 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
+ }
1363
1372
1364
1373
// Clamp the max angle, so we don't end up trying to walk at a 80 degree angle up sheer walls
1365
1374
const float maxAngleDegrees = 40 .0F ;
1366
- float terrainRotationDegs = std::clamp ((hitPosRight - hitPosLeft). GetAbsDegAngle () , -maxAngleDegrees, maxAngleDegrees);
1375
+ float terrainRotationDegs = std::clamp (angle , -maxAngleDegrees, maxAngleDegrees);
1367
1376
1368
1377
// const float fastMovementAngleReduction = 10.0F;
1369
1378
// const float ourMaxMovementSpeed = std::max(m_Paths[FGROUND][WALK].GetSpeed(), m_Paths[BGROUND][WALK].GetSpeed()) * 0.5F;
0 commit comments