From 0c645e8b0c570d5b47f86c7709a2a89c2281f688 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 29 Oct 2024 21:59:21 +0100 Subject: [PATCH] Fix root animation in blend spaces when one of the animations doesn't use root motion but animated root node channel --- .../Engine/Animations/Graph/AnimGroup.Animation.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp index 2103bb8cd..0eb7c952c 100644 --- a/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp +++ b/Source/Engine/Animations/Graph/AnimGroup.Animation.cpp @@ -356,9 +356,10 @@ void AnimGraphExecutor::ProcessAnimation(AnimGraphImpulse* nodes, AnimGraphNode* if (_rootMotionMode == RootMotionExtraction::Enable && nodeToChannel != -1) { // Get the root bone transformation - Transform rootBefore = refPose; + Transform rootBefore = refPose, rootNow = refPose; const NodeAnimationData& rootChannel = anim->Data.Channels[nodeToChannel]; rootChannel.Evaluate(animPrevPos, &rootBefore, false); + rootChannel.Evaluate(animPos, &rootNow, false); // Check if animation looped if (animPos < animPrevPos) @@ -375,18 +376,18 @@ void AnimGraphExecutor::ProcessAnimation(AnimGraphImpulse* nodes, AnimGraphNode* // (end - before + now - begin) // It sums the motion since the last update to anim end and since the start to now if (motionPosition) - srcNode.Translation = (rootEnd.Translation - rootBefore.Translation + rootNode.Translation - rootBegin.Translation) * motionPositionMask; + srcNode.Translation = (rootEnd.Translation - rootBefore.Translation + rootNow.Translation - rootBegin.Translation) * motionPositionMask; if (motionRotation) - srcNode.Orientation = (rootBefore.Orientation.Conjugated() * rootEnd.Orientation) * (rootBegin.Orientation.Conjugated() * rootNode.Orientation); + srcNode.Orientation = (rootBefore.Orientation.Conjugated() * rootEnd.Orientation) * (rootBegin.Orientation.Conjugated() * rootNow.Orientation); } else { // Simple motion delta // (now - before) if (motionPosition) - srcNode.Translation = (rootNode.Translation - rootBefore.Translation) * motionPositionMask; + srcNode.Translation = (rootNow.Translation - rootBefore.Translation) * motionPositionMask; if (motionRotation) - srcNode.Orientation = rootBefore.Orientation.Conjugated() * rootNode.Orientation; + srcNode.Orientation = rootBefore.Orientation.Conjugated() * rootNow.Orientation; } // Convert root motion from local-space to the actor-space (eg. if root node is not actually a root and its parents have rotation/scale)