Răsfoiți Sursa

Merge pull request #167 from aws-lumberyard-dev/mps_flycamera_jitter

Remove FlyCameraComponent and update SimplePlayerCamera interpolation
puvvadar 3 ani în urmă
părinte
comite
eb9585d5fa

+ 25 - 9
Gem/Code/Source/Components/NetworkSimplePlayerCameraComponent.cpp

@@ -10,11 +10,11 @@
 #include <Source/Components/NetworkSimplePlayerCameraComponent.h>
 #include <AzCore/Component/TransformBus.h>
 #include <AzFramework/Components/CameraBus.h>
+#include <Multiplayer/IMultiplayer.h>
 
 namespace MultiplayerSample
 {
     AZ_CVAR(AZ::Vector3, cl_cameraOffset, AZ::Vector3(0.0f, -5.0f, 3.0f), nullptr, AZ::ConsoleFunctorFlags::Null, "Offset to use for the player camera");
-    AZ_CVAR(float, cl_cameraBlendSpeed, 0.25f, nullptr, AZ::ConsoleFunctorFlags::Null, "Rate to blend camera to latest transform");
 
     NetworkSimplePlayerCameraComponentController::NetworkSimplePlayerCameraComponentController(NetworkSimplePlayerCameraComponent& parent)
         : NetworkSimplePlayerCameraComponentControllerBase(parent)
@@ -63,20 +63,36 @@ namespace MultiplayerSample
         return GetAimAngles().GetY();
     }
 
+    float NetworkSimplePlayerCameraComponentController::GetCameraYawPrevious() const
+    {
+        return GetAimAnglesPrevious().GetZ();
+    }
+
+    float NetworkSimplePlayerCameraComponentController::GetCameraPitchPrevious() const
+    {
+        return GetAimAnglesPrevious().GetX();
+    }
+
+    float NetworkSimplePlayerCameraComponentController::GetCameraRollPrevious() const
+    {
+        return GetAimAnglesPrevious().GetY();
+    }
+
     void NetworkSimplePlayerCameraComponentController::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
     {
         if (m_activeCameraEntity != nullptr && m_activeCameraEntity->GetState() == AZ::Entity::State::Active)
         {
             const AZ::Quaternion targetRotation = AZ::Quaternion::CreateRotationZ(GetCameraYaw()) * AZ::Quaternion::CreateRotationX(GetCameraPitch());
-            const AZ::Quaternion currentRotation = m_activeCameraEntity->GetTransform()->GetWorldTM().GetRotation();
-            AZ::Quaternion aimRotation;
-            if(GetSyncAimImmediate())
-            {
-                aimRotation = targetRotation;
-            }
-            else
+            const float blendFactor = Multiplayer::GetMultiplayer()->GetCurrentBlendFactor();
+            
+            AZ::Quaternion aimRotation = targetRotation;
+            if (!GetSyncAimImmediate() && !AZ::IsClose(blendFactor, 1.0f))
             {
-                aimRotation = currentRotation.Slerp(targetRotation, cl_cameraBlendSpeed).GetNormalized();
+                const AZ::Quaternion prevRotation = AZ::Quaternion::CreateRotationZ(GetCameraYawPrevious()) * AZ::Quaternion::CreateRotationX(GetCameraPitchPrevious());
+                if (!prevRotation.IsClose(targetRotation))
+                {
+                    aimRotation = prevRotation.Slerp(targetRotation, blendFactor).GetNormalized();
+                }
             }
             const AZ::Vector3 targetTranslation = GetEntity()->GetTransform()->GetWorldTM().GetTranslation();
             const AZ::Vector3 cameraOffset = aimRotation.TransformVector(cl_cameraOffset);

+ 4 - 0
Gem/Code/Source/Components/NetworkSimplePlayerCameraComponent.h

@@ -26,6 +26,10 @@ namespace MultiplayerSample
         float GetCameraPitch() const;
         float GetCameraRoll() const;
 
+        float GetCameraYawPrevious() const;
+        float GetCameraPitchPrevious() const;
+        float GetCameraRollPrevious() const;
+
     private:
         //! AZ::TickBus interface
         //! @{

+ 0 - 7
Levels/SampleBase/SampleBase.prefab

@@ -1925,13 +1925,6 @@
                     "$type": "EditorInspectorComponent",
                     "Id": 154105298091518109
                 },
-                "Component_[15452140819580244001]": {
-                    "$type": "GenericComponentWrapper",
-                    "Id": 15452140819580244001,
-                    "m_template": {
-                        "$type": "FlyCameraInputComponent"
-                    }
-                },
                 "Component_[17443734220531699641]": {
                     "$type": "EditorOnlyEntityComponent",
                     "Id": 17443734220531699641