diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRenderer.cpp b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRenderer.cpp index 7b20bf2f5d..faa033956a 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRenderer.cpp +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRenderer.cpp @@ -181,15 +181,26 @@ namespace EMStudio ResetEnvironment(); } - AZ::Vector3 AnimViewportRenderer::GetCenter() const + AZ::Vector3 AnimViewportRenderer::GetCharacterCenter() const { AZ::Vector3 result = AZ::Vector3::CreateZero(); if (!m_actorEntities.empty()) { + // Find the actor instance and calculate the center from aabb. + AZ::Vector3 actorCenter = AZ::Vector3::CreateZero(); + EMotionFX::Integration::ActorComponent* actorComponent = + m_actorEntities[0]->FindComponent(); + EMotionFX::ActorInstance* actorInstance = actorComponent->GetActorInstance(); + if (actorInstance) + { + actorCenter += actorInstance->GetAabb().GetCenter(); + } + // Just return the position of the first entity. AZ::Transform worldTransform; AZ::TransformBus::EventResult(worldTransform, m_actorEntities[0]->GetId(), &AZ::TransformBus::Events::GetWorldTM); result = worldTransform.GetTranslation(); + result += actorCenter; } return result; diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRenderer.h b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRenderer.h index cd1c567743..1de4cbdb1c 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRenderer.h +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportRenderer.h @@ -50,7 +50,7 @@ namespace EMStudio void Reinit(); //! Return the center position of the existing objects. - AZ::Vector3 GetCenter() const; + AZ::Vector3 GetCharacterCenter() const; private: diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportWidget.cpp b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportWidget.cpp index a6980c18ef..2e05864adc 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportWidget.cpp +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportWidget.cpp @@ -126,8 +126,7 @@ namespace EMStudio void AnimViewportWidget::SetCameraViewMode([[maybe_unused]]CameraViewMode mode) { // Set the camera view mode. - AZ::Vector3 targetPosition = m_renderer->GetCenter(); - targetPosition.SetZ(targetPosition.GetY() + TargetCenterOffsetZ); + const AZ::Vector3 targetPosition = m_renderer->GetCharacterCenter(); AZ::Vector3 cameraPosition; switch (mode) { diff --git a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportWidget.h b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportWidget.h index a0ba3a83c6..2d43b7ade7 100644 --- a/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportWidget.h +++ b/Gems/AtomLyIntegration/EMotionFXAtom/Code/Tools/EMStudio/AnimViewportWidget.h @@ -35,7 +35,6 @@ namespace EMStudio void SetCameraViewMode(CameraViewMode mode); static constexpr float CameraDistance = 2.0f; - static constexpr float TargetCenterOffsetZ = 1.0f; AZStd::unique_ptr m_renderer; AZStd::shared_ptr m_rotateCamera;