From 7e3d19196d722e1bf150365c0af8fe8b7f47498d Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Tue, 1 Sep 2020 00:37:37 +0200 Subject: [PATCH] Fix #5586 --- apps/openmw/mwclass/npc.cpp | 2 ++ apps/openmw/mwmechanics/character.cpp | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index b89d79fc9b..4aab95f9d1 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -938,6 +938,8 @@ namespace MWClass float Npc::getMaxSpeed(const MWWorld::Ptr& ptr) const { + // TODO: This function is called several times per frame for each NPC. + // It would be better to calculate it only once per frame for each NPC and save the result in CreatureStats. const MWMechanics::CreatureStats& stats = getCreatureStats(ptr); if (stats.isParalyzed() || stats.getKnockedDown() || stats.isDead()) return 0.f; diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 5d102f69ea..32f8f6f2ae 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -1965,8 +1965,11 @@ void CharacterController::update(float duration, bool animationOnly) vec.normalize(); float effectiveRotation = rot.z(); + bool canMove = cls.getMaxSpeed(mPtr) > 0; static const bool turnToMovementDirection = Settings::Manager::getBool("turn to movement direction", "Game"); - if (turnToMovementDirection && !isFirstPersonPlayer) + if (!turnToMovementDirection || isFirstPersonPlayer) + movementSettings.mIsStrafing = std::abs(vec.x()) > std::abs(vec.y()) * 2; + else if (canMove) { float targetMovementAngle = vec.y() >= 0 ? std::atan2(-vec.x(), vec.y()) : std::atan2(vec.x(), -vec.y()); movementSettings.mIsStrafing = (stats.getDrawState() != MWMechanics::DrawState_Nothing || inwater) @@ -1986,8 +1989,6 @@ void CharacterController::update(float duration, bool animationOnly) stats.setSideMovementAngle(stats.getSideMovementAngle() + delta); effectiveRotation += delta; } - else - movementSettings.mIsStrafing = std::abs(vec.x()) > std::abs(vec.y()) * 2; mAnimation->setLegsYawRadians(stats.getSideMovementAngle()); if (stats.getDrawState() == MWMechanics::DrawState_Nothing || inwater)