From a455b99ed63111d32bd1264c12d0eeeac66257c5 Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Sat, 27 Jun 2020 20:43:08 +0200 Subject: [PATCH] Fix incorrect speed for creatures, that is caused by https://gitlab.com/OpenMW/openmw/-/merge_requests/245/diffs?commit_id=eebbacd8b4ab22b3e824538df2d7faec0038c1a1 --- apps/openmw/mwmechanics/character.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index da862b7eab..cf09fa6f74 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -2368,8 +2368,21 @@ void CharacterController::update(float duration, bool animationOnly) moved.y() *= scale; // Ensure we're moving in generally the right direction... - if(speed > 0.f && (movement - moved).length2() * 4 > moved.length2()) - moved = movement; + if(speed > 0.f) + { + float l = moved.length(); + if (std::abs(movement.x() - moved.x()) > std::abs(moved.x()) / 2 || + std::abs(movement.y() - moved.y()) > std::abs(moved.y()) / 2 || + std::abs(movement.z() - moved.z()) > std::abs(moved.z()) / 2) + { + moved = movement; + // For some creatures getSpeed doesn't work, so we adjust speed to the animation. + // TODO: Fix Creature::getSpeed. + float newLength = moved.length(); + if (newLength > 0 && !cls.isNpc()) + moved *= (l / newLength); + } + } if (mFloatToSurface && cls.isActor() && cls.getCreatureStats(mPtr).isDead() && cls.canSwim(mPtr)) moved.z() = 1.0;