Pārlūkot izejas kodu

Updates to make animations and character movement functional

karlberg 4 gadi atpakaļ
vecāks
revīzija
3d69acc0c5

+ 5 - 4
Gem/Code/Source/Components/AnimatedHitVolumesComponent.cpp

@@ -18,6 +18,7 @@
 #include <AzFramework/Physics/Material.h>
 #include <AzFramework/Physics/Material.h>
 #include <MCore/Source/AzCoreConversions.h>
 #include <MCore/Source/AzCoreConversions.h>
 #include <Integration/ActorComponentBus.h>
 #include <Integration/ActorComponentBus.h>
+#include <Integration/AnimGraphNetworkingBus.h>
 
 
 namespace MultiplayerSample
 namespace MultiplayerSample
 {
 {
@@ -131,10 +132,10 @@ namespace MultiplayerSample
 
 
     void AnimatedHitVolumesComponent::Update([[maybe_unused]] AZ::TimeMs deltaTimeMs)
     void AnimatedHitVolumesComponent::Update([[maybe_unused]] AZ::TimeMs deltaTimeMs)
     {
     {
-        if (m_animatedHitVolumes.size() <= 0)
-        {
-            CreateHitVolumes();
-        }
+        //if (m_animatedHitVolumes.size() <= 0)
+        //{
+        //    CreateHitVolumes();
+        //}
 
 
         AZ::Vector3 position, scale;
         AZ::Vector3 position, scale;
         AZ::Quaternion rotation;
         AZ::Quaternion rotation;

+ 1 - 1
Gem/Code/Source/Components/CharacterComponent.cpp

@@ -77,7 +77,7 @@ namespace MultiplayerSample
 
 
     AZ::Vector3 CharacterComponentController::TryMoveWithVelocity(const AZ::Vector3& velocity, float deltaTime)
     AZ::Vector3 CharacterComponentController::TryMoveWithVelocity(const AZ::Vector3& velocity, float deltaTime)
     {
     {
-        if (GetParent().m_physicsCharacter == nullptr)
+        if ((GetParent().m_physicsCharacter == nullptr) || (velocity.GetLengthSq() <= 0.0f))
         {
         {
             return GetNetworkTransformComponentController()->GetTranslation();
             return GetNetworkTransformComponentController()->GetTranslation();
         }
         }

+ 25 - 2
Gem/Code/Source/Components/NetworkAnimationComponent.cpp

@@ -14,6 +14,7 @@
 #include <Source/Components/WasdPlayerMovementComponent.h>
 #include <Source/Components/WasdPlayerMovementComponent.h>
 #include <Integration/AnimGraphComponentBus.h>
 #include <Integration/AnimGraphComponentBus.h>
 #include <Integration/AnimationBus.h>
 #include <Integration/AnimationBus.h>
+#include <Integration/AnimGraphNetworkingBus.h>
 
 
 namespace MultiplayerSample
 namespace MultiplayerSample
 {
 {
@@ -38,6 +39,7 @@ namespace MultiplayerSample
         AZ::TickBus::Handler::BusConnect();
         AZ::TickBus::Handler::BusConnect();
 
 
         m_actorRequests = EMotionFX::Integration::ActorComponentRequestBus::FindFirstHandler(GetEntityId());
         m_actorRequests = EMotionFX::Integration::ActorComponentRequestBus::FindFirstHandler(GetEntityId());
+        m_networkRequests = EMotionFX::AnimGraphComponentNetworkRequestBus::FindFirstHandler(GetEntityId());
         m_animationGraph = EMotionFX::Integration::AnimGraphComponentRequestBus::FindFirstHandler(GetEntityId());
         m_animationGraph = EMotionFX::Integration::AnimGraphComponentRequestBus::FindFirstHandler(GetEntityId());
 
 
         if (m_animationGraph != nullptr)
         if (m_animationGraph != nullptr)
@@ -48,12 +50,13 @@ namespace MultiplayerSample
         }
         }
 
 
         EMotionFX::Integration::ActorComponentNotificationBus::Handler::BusConnect(GetEntityId());
         EMotionFX::Integration::ActorComponentNotificationBus::Handler::BusConnect(GetEntityId());
+        EMotionFX::Integration::AnimGraphComponentNotificationBus::Handler::BusConnect(GetEntityId());
     }
     }
 
 
     void NetworkAnimationComponent::OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
     void NetworkAnimationComponent::OnDeactivate([[maybe_unused]] Multiplayer::EntityIsMigrating entityIsMigrating)
     {
     {
-        AZ::TickBus::Handler::BusDisconnect();
         EMotionFX::Integration::ActorComponentNotificationBus::Handler::BusDisconnect();
         EMotionFX::Integration::ActorComponentNotificationBus::Handler::BusDisconnect();
+        AZ::TickBus::Handler::BusDisconnect();
     }
     }
 
 
     int32_t NetworkAnimationComponent::GetBoneIdByName(const char* boneName) const
     int32_t NetworkAnimationComponent::GetBoneIdByName(const char* boneName) const
@@ -87,7 +90,14 @@ namespace MultiplayerSample
 
 
     void NetworkAnimationComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
     void NetworkAnimationComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time)
     {
     {
-        if ((m_animationGraph != nullptr) && (m_movementSpeedParamId == InvalidParamIndex))
+        if (m_animationGraph == nullptr || m_networkRequests == nullptr)
+        {
+            return;
+        }
+
+        m_networkRequests->UpdateActorExternal(deltaTime);
+
+        if (m_movementSpeedParamId == InvalidParamIndex)
         {
         {
             m_movementSpeedParamId = m_animationGraph->FindParameterIndex(GetMovementSpeedParamName().c_str());
             m_movementSpeedParamId = m_animationGraph->FindParameterIndex(GetMovementSpeedParamName().c_str());
             m_attackParamId = m_animationGraph->FindParameterIndex(GetAttackParamName().c_str());
             m_attackParamId = m_animationGraph->FindParameterIndex(GetAttackParamName().c_str());
@@ -130,4 +140,17 @@ namespace MultiplayerSample
     {
     {
         m_actorRequests = nullptr;
         m_actorRequests = nullptr;
     }
     }
+
+    void NetworkAnimationComponent::OnAnimGraphInstanceCreated([[maybe_unused]] EMotionFX::AnimGraphInstance* animGraphInstance)
+    {
+        // We don't need any more notifications
+        EMotionFX::Integration::AnimGraphComponentNotificationBus::Handler::BusDisconnect();
+
+        // Disable automatic EMotionFX updates of transform, network has control
+        if (m_networkRequests != nullptr)
+        {
+            constexpr bool isAuthoritative = true;
+            m_networkRequests->CreateSnapshot(isAuthoritative);
+        }
+    }
 }
 }

+ 17 - 5
Gem/Code/Source/Components/NetworkAnimationComponent.h

@@ -15,11 +15,16 @@
 #include <Source/AutoGen/NetworkAnimationComponent.AutoComponent.h>
 #include <Source/AutoGen/NetworkAnimationComponent.AutoComponent.h>
 #include <AzCore/Component/TickBus.h>
 #include <AzCore/Component/TickBus.h>
 #include <Integration/ActorComponentBus.h>
 #include <Integration/ActorComponentBus.h>
+#include <Integration/AnimGraphComponentBus.h>
 
 
-namespace EMotionFX::Integration
+namespace EMotionFX
 {
 {
-    class ActorComponentRequests;
-    class AnimGraphComponentRequests;
+    class AnimGraphComponentNetworkRequests;
+    namespace Integration
+    {
+        class ActorComponentRequests;
+        class AnimGraphComponentRequests;
+    }
 }
 }
 
 
 namespace MultiplayerSample
 namespace MultiplayerSample
@@ -33,6 +38,7 @@ namespace MultiplayerSample
         : public NetworkAnimationComponentBase
         : public NetworkAnimationComponentBase
         , public AZ::TickBus::Handler
         , public AZ::TickBus::Handler
         , private EMotionFX::Integration::ActorComponentNotificationBus::Handler
         , private EMotionFX::Integration::ActorComponentNotificationBus::Handler
+        , private EMotionFX::Integration::AnimGraphComponentNotificationBus::Handler
     {
     {
     public:
     public:
         AZ_MULTIPLAYER_COMPONENT(MultiplayerSample::NetworkAnimationComponent, s_networkAnimationComponentConcreteUuid, MultiplayerSample::NetworkAnimationComponentBase);
         AZ_MULTIPLAYER_COMPONENT(MultiplayerSample::NetworkAnimationComponent, s_networkAnimationComponentConcreteUuid, MultiplayerSample::NetworkAnimationComponentBase);
@@ -57,11 +63,17 @@ namespace MultiplayerSample
 
 
         //! EMotionFX::Integration::ActorComponentNotificationBus::Handler
         //! EMotionFX::Integration::ActorComponentNotificationBus::Handler
         //! @{
         //! @{
-        void OnActorInstanceCreated(EMotionFX::ActorInstance* actorInstance);
-        void OnActorInstanceDestroyed(EMotionFX::ActorInstance* actorInstance);
+        void OnActorInstanceCreated(EMotionFX::ActorInstance* actorInstance) override;
+        void OnActorInstanceDestroyed(EMotionFX::ActorInstance* actorInstance) override;
+        //! @}
+
+        //! EMotionFX::Integration::AnimGraphComponentNotificationBus::Handler
+        //! @{
+        void OnAnimGraphInstanceCreated(EMotionFX::AnimGraphInstance* animGraphInstance) override;
         //! @}
         //! @}
 
 
         EMotionFX::Integration::ActorComponentRequests* m_actorRequests = nullptr;
         EMotionFX::Integration::ActorComponentRequests* m_actorRequests = nullptr;
+        EMotionFX::AnimGraphComponentNetworkRequests* m_networkRequests = nullptr;
         EMotionFX::Integration::AnimGraphComponentRequests* m_animationGraph = nullptr;
         EMotionFX::Integration::AnimGraphComponentRequests* m_animationGraph = nullptr;
 
 
         // Hardcoded parameters, be nice if this was flexible and configurable from within the editor
         // Hardcoded parameters, be nice if this was flexible and configurable from within the editor

+ 11 - 11
Gem/Code/Source/Components/WasdPlayerMovementComponent.cpp

@@ -19,7 +19,6 @@
 namespace MultiplayerSample
 namespace MultiplayerSample
 {
 {
     AZ_CVAR(float, cl_WasdStickAccel, 5.0f, nullptr, AZ::ConsoleFunctorFlags::Null, "The linear acceleration to apply to WASD inputs to simulate analog stick controls");
     AZ_CVAR(float, cl_WasdStickAccel, 5.0f, nullptr, AZ::ConsoleFunctorFlags::Null, "The linear acceleration to apply to WASD inputs to simulate analog stick controls");
-    AZ_CVAR(bool, override_forward, false, nullptr, AZ::ConsoleFunctorFlags::Null, "debug override forward key value");
 
 
     void WasdPlayerMovementComponent::WasdPlayerMovementComponent::Reflect(AZ::ReflectContext* context)
     void WasdPlayerMovementComponent::WasdPlayerMovementComponent::Reflect(AZ::ReflectContext* context)
     {
     {
@@ -90,7 +89,7 @@ namespace MultiplayerSample
         // Movement axis
         // Movement axis
         // Since we're on a keyboard, this adds a touch of an acceleration curve to the keyboard inputs
         // Since we're on a keyboard, this adds a touch of an acceleration curve to the keyboard inputs
         // This is so that tapping the keyboard moves the virtual stick less than just holding it down
         // This is so that tapping the keyboard moves the virtual stick less than just holding it down
-        m_forwardWeight = std::min<float>(m_forwardDown || override_forward ? m_forwardWeight + cl_WasdStickAccel * deltaTime : 0.0f, 1.0f);
+        m_forwardWeight = std::min<float>(m_forwardDown ? m_forwardWeight + cl_WasdStickAccel * deltaTime : 0.0f, 1.0f);
         m_leftWeight = std::min<float>(m_leftDown ? m_leftWeight + cl_WasdStickAccel * deltaTime : 0.0f, 1.0f);
         m_leftWeight = std::min<float>(m_leftDown ? m_leftWeight + cl_WasdStickAccel * deltaTime : 0.0f, 1.0f);
         m_backwardWeight = std::min<float>(m_backwardDown ? m_backwardWeight + cl_WasdStickAccel * deltaTime : 0.0f, 1.0f);
         m_backwardWeight = std::min<float>(m_backwardDown ? m_backwardWeight + cl_WasdStickAccel * deltaTime : 0.0f, 1.0f);
         m_rightWeight = std::min<float>(m_rightDown ? m_rightWeight + cl_WasdStickAccel * deltaTime : 0.0f, 1.0f);
         m_rightWeight = std::min<float>(m_rightDown ? m_rightWeight + cl_WasdStickAccel * deltaTime : 0.0f, 1.0f);
@@ -174,26 +173,27 @@ namespace MultiplayerSample
         const float fwdBack = wasdInput.m_forwardAxis;
         const float fwdBack = wasdInput.m_forwardAxis;
         const float leftRight = wasdInput.m_strafeAxis;
         const float leftRight = wasdInput.m_strafeAxis;
 
 
-        if (wasdInput.m_sprint)
+        // Note that we really want to be setting a velocity anim graph param so the character strafes correctly
+        if (fwdBack < 0.0f)
         {
         {
-            if (fwdBack < 0.0f)
+            SetSpeed(GetCharacterComponentController()->GetReverseSprintSpeed());
+        }
+        else
+        {
+            if (wasdInput.m_sprint)
             {
             {
-                SetSpeed(GetCharacterComponentController()->GetReverseSprintSpeed());
+                SetSpeed(GetCharacterComponentController()->GetSprintSpeed());
             }
             }
             else
             else
             {
             {
-                SetSpeed(GetCharacterComponentController()->GetSprintSpeed());
+                SetSpeed(GetCharacterComponentController()->GetWalkSpeed());
             }
             }
         }
         }
-        else
-        {
-            SetSpeed(GetCharacterComponentController()->GetWalkSpeed());
-        }
 
 
         // Not moving?
         // Not moving?
         if (fwdBack == 0.0f && leftRight == 0.0f)
         if (fwdBack == 0.0f && leftRight == 0.0f)
         {
         {
-            // No velocity
+            SetSpeed(0.0f);
             m_velocity = AZ::Vector3::CreateZero();
             m_velocity = AZ::Vector3::CreateZero();
         }
         }
         else
         else

+ 2 - 2
Jack/Simple_JackLocomotion.motionset

@@ -1,3 +1,3 @@
 version https://git-lfs.github.com/spec/v1
 version https://git-lfs.github.com/spec/v1
-oid sha256:ed7967825e4dc055c1427998f3d198e235ff0fc603f218e3ba31d061e0fe1c7c
-size 1302
+oid sha256:9686ae50a4e2e4000c4f5e8db3118e9bcd705f263a178f53e8dd6bc3eba0ed4c
+size 7543

+ 10 - 10
Prefabs/Player.prefab

@@ -116,9 +116,9 @@
                     "Parent Entity": "Entity_[1419387525450]",
                     "Parent Entity": "Entity_[1419387525450]",
                     "Cached World Transform": {
                     "Cached World Transform": {
                         "Translation": [
                         "Translation": [
-                            -0.01572617143392563,
-                            19.999988555908204,
-                            0.015726406127214433
+                            -0.013710042461752892,
+                            19.999990463256837,
+                            0.01370984222739935
                         ]
                         ]
                     },
                     },
                     "Cached World Transform Parent": "Entity_[1419387525450]"
                     "Cached World Transform Parent": "Entity_[1419387525450]"
@@ -170,14 +170,14 @@
                     "Id": 7398251875150394377,
                     "Id": 7398251875150394377,
                     "m_template": {
                     "m_template": {
                         "$type": "MultiplayerSample::CharacterComponent",
                         "$type": "MultiplayerSample::CharacterComponent",
-                        "WalkSpeed": 0.08761131763458252,
-                        "SprintSpeed": 0.8999999761581421,
+                        "WalkSpeed": 2.0,
+                        "SprintSpeed": 4.0,
                         "ReverseSprintSpeed": 1.0,
                         "ReverseSprintSpeed": 1.0,
-                        "SpawnTimerDuration": -1.7014635547491818e38,
-                        "DeathTimerDuration": 0.04500001668930054,
+                        "SpawnTimerDuration": 10.0,
+                        "DeathTimerDuration": 10.0,
                         "RespawnOnDeath": true,
                         "RespawnOnDeath": true,
                         "StepHeight": 1.0,
                         "StepHeight": 1.0,
-                        "SlopeLimitDegrees": -1.7146521915939559e38,
+                        "SlopeLimitDegrees": 30,
                         "ContactOffset": 0.04500001668930054
                         "ContactOffset": 0.04500001668930054
                     }
                     }
                 },
                 },
@@ -216,7 +216,7 @@
                         },
                         },
                         "assetHint": "jack/simple_jacklocomotion.motionset"
                         "assetHint": "jack/simple_jacklocomotion.motionset"
                     },
                     },
-                    "ActiveMotionSetName": "Simple_JackLocomotion"
+                    "ActiveMotionSetName": "Cowboy"
                 },
                 },
                 "Component_[13362124592556856876]": {
                 "Component_[13362124592556856876]": {
                     "$type": "GenericComponentWrapper",
                     "$type": "GenericComponentWrapper",
@@ -230,7 +230,7 @@
                     "Id": 11996978980717063697,
                     "Id": 11996978980717063697,
                     "m_template": {
                     "m_template": {
                         "$type": "MultiplayerSample::NetworkAnimationComponent",
                         "$type": "MultiplayerSample::NetworkAnimationComponent",
-                        "MaxSpeed": -1.7877743184709537e26,
+                        "MaxSpeed": 4.0,
                         "MovementSpeedParamName": "Speed",
                         "MovementSpeedParamName": "Speed",
                         "AttackParamName": "Attack",
                         "AttackParamName": "Attack",
                         "JumpParamName": "Jump"
                         "JumpParamName": "Jump"