Explorar o código

Merge pull request #275 from aws-lumberyard-dev/SprintToggle

Sprint toggle
Karl Berg %!s(int64=2) %!d(string=hai) anos
pai
achega
4cf3572c40

+ 16 - 5
Gem/Code/Source/Components/NetworkPlayerMovementComponent.cpp

@@ -153,6 +153,13 @@ namespace MultiplayerSample
 
         if (networkMatchComponent && (networkMatchComponent->PlayerActionsAllowed() == AllowedPlayerActions::All))
         {
+            // Check if the user requested to toggle sprint-state
+            if (m_toggleSprint)
+            {
+                m_sprinting = !m_sprinting;
+                m_toggleSprint = false;
+            }
+
             // Movement axis
             // 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
@@ -274,6 +281,14 @@ namespace MultiplayerSample
         GetNetworkAnimationComponentController()->ModifyActiveAnimStates().SetBit(
             aznumeric_cast<uint32_t>(CharacterAnimState::Falling), isFalling);
 
+        // If we're still on the ground, then zero out our velocity from external forces
+        // This prevents us from sliding along the ground after we land
+        PhysX::CharacterGameplayRequestBus::EventResult(onGround, GetEntityId(), &PhysX::CharacterGameplayRequestBus::Events::IsOnGround);
+        if (onGround)
+        {
+            SetVelocityFromExternalSources(AZ::Vector3::CreateZero());
+        }
+
         // At the end, track whether or not we were on the ground for this input so we can compare states when processing the next input.
         SetWasOnGround(onGround);
     }
@@ -542,7 +557,7 @@ namespace MultiplayerSample
         }
         else if (*inputId == SprintEventId)
         {
-            m_sprinting = true;
+            m_toggleSprint = true;
         }
         else if (*inputId == JumpEventId)
         {
@@ -589,10 +604,6 @@ namespace MultiplayerSample
         {
             m_rightDown = false;
         }
-        else if (*inputId == SprintEventId)
-        {
-            m_sprinting = false;
-        }
         else if (*inputId == JumpEventId)
         {
             m_jumping = false;

+ 2 - 0
Gem/Code/Source/Components/NetworkPlayerMovementComponent.h

@@ -101,6 +101,8 @@ namespace MultiplayerSample
         float m_viewYaw = 0.0f;
         float m_viewPitch = 0.0f;
 
+        bool m_toggleSprint = false;
+
         bool m_forwardDown = false;
         bool m_leftDown = false;
         bool m_backwardDown = false;