Sfoglia il codice sorgente

Addressing various issues causing shot desyncs

Signed-off-by: puvvadar <[email protected]>
puvvadar 3 anni fa
parent
commit
44ac76669a

+ 1 - 0
Gem/Code/Source/AutoGen/NetworkWeaponsComponent.AutoComponent.xml

@@ -16,6 +16,7 @@
 
     <NetworkInput Type="bool" Name="Draw" Init="false" />
     <NetworkInput Type="WeaponActivationBitset" Name="Firing"  Init="" />
+	<NetworkInput Type="AZ::Vector3" Name="FireTranslation" Init="" Container="Array" Count="MaxWeaponsPerComponent"/>
 
     <NetworkProperty Type="FireParams"  Name="ActivationParams" Init=""  Container="Array" Count="MaxWeaponsPerComponent" ReplicateFrom="Authority" ReplicateTo="Client"     IsPublic="false" IsRewindable="false" IsPredictable="false" ExposeToEditor="false" GenerateEventBindings="false" Description="Parameters for the current weapon activation" />
     <NetworkProperty Type="uint8_t"     Name="ActivationCounts" Init="0" Container="Array" Count="MaxWeaponsPerComponent" ReplicateFrom="Authority" ReplicateTo="Client"     IsPublic="false" IsRewindable="false" IsPredictable="false" ExposeToEditor="false" GenerateEventBindings="true"  Description="The number of activations" />

+ 18 - 17
Gem/Code/Source/Components/NetworkWeaponsComponent.cpp

@@ -91,24 +91,10 @@ namespace MultiplayerSample
 
     void NetworkWeaponsComponent::ActivateWeaponWithParams(WeaponIndex weaponIndex, WeaponState& weaponState, const FireParams& fireParams, bool validateActivations)
     {
-        const uint32_t weaponIndexInt = aznumeric_cast<uint32_t>(weaponIndex);
-
-        // Temp hack for weapon firing due to late ebus binding in 1.14
-        if (m_fireBoneJointIds[weaponIndexInt] == InvalidBoneId)
-        {
-            const char* fireBoneName = GetFireBoneNames(weaponIndexInt).c_str();
-            m_fireBoneJointIds[weaponIndexInt] = GetNetworkAnimationComponent()->GetBoneIdByName(fireBoneName);
-        }
-
-        AZ::Transform fireBoneTransform;
-        if (!GetNetworkAnimationComponent()->GetJointTransformById(m_fireBoneJointIds[weaponIndexInt], fireBoneTransform))
-        {
-            AZLOG_WARN("Failed to get transform for fire bone %s, joint Id %u", GetFireBoneNames(weaponIndexInt).c_str(), m_fireBoneJointIds[weaponIndexInt]);
-        }
-
-        const AZ::Vector3    position = fireBoneTransform.GetTranslation();
+        const AZ::Vector3    position = fireParams.m_sourcePosition;
         const AZ::Quaternion orientation = AZ::Quaternion::CreateShortestArc(AZ::Vector3::CreateAxisX(), (fireParams.m_targetPosition - position).GetNormalized());
         const AZ::Transform  transform = AZ::Transform::CreateFromQuaternionAndTranslation(orientation, position);
+
         ActivateEvent activateEvent{ transform, fireParams.m_targetPosition, GetNetEntityId(), Multiplayer::InvalidNetEntityId };
 
         IWeapon* weapon = GetWeapon(weaponIndex);
@@ -335,6 +321,21 @@ namespace MultiplayerSample
 
         weaponInput->m_draw = m_weaponDrawn;
         weaponInput->m_firing = m_weaponFiring;
+
+        uint32_t weaponIndexInt = 0;
+        if (weaponInput->m_firing.GetBit(weaponIndexInt))
+        {
+            // Temp hack for weapon firing due to late ebus binding in 1.14
+            const char* fireBoneName = GetFireBoneNames(weaponIndexInt).c_str();
+            int32_t boneIdx = GetNetworkAnimationComponentController()->GetParent().GetBoneIdByName(fireBoneName);
+
+            AZ::Transform fireBoneTransform;
+            if (!GetNetworkAnimationComponentController()->GetParent().GetJointTransformById(boneIdx, fireBoneTransform))
+            {
+                AZLOG_WARN("Failed to get transform for fire bone joint Id %u", boneIdx);
+            }
+            weaponInput->m_fireTranslation = fireBoneTransform.GetTranslation();
+        }
     }
 
     void NetworkWeaponsComponentController::ProcessInput(Multiplayer::NetworkInput& input, [[maybe_unused]] float deltaTime)
@@ -362,7 +363,7 @@ namespace MultiplayerSample
                 // TODO: This should probably be a physx raycast out to some maxDistance
                 const AZ::Vector3 fwd = AZ::Vector3::CreateAxisY();
                 const AZ::Vector3 aimTarget = worldTm.GetTranslation() + aimRotation.TransformVector(fwd * 5.0f);
-                FireParams fireParams{ aimTarget, Multiplayer::InvalidNetEntityId };
+                FireParams fireParams{ aimTarget, weaponInput->m_fireTranslation, Multiplayer::InvalidNetEntityId };
                 TryStartFire(aznumeric_cast<WeaponIndex>(weaponIndexInt), fireParams);
             }
         }

+ 4 - 2
Gem/Code/Source/Weapons/SceneQuery.cpp

@@ -13,6 +13,7 @@
 #include <Multiplayer/IMultiplayer.h>
 #include <Multiplayer/NetworkEntity/INetworkEntityManager.h>
 #include <Multiplayer/NetworkTime/INetworkTime.h>
+#include <PhysX/NativeTypeIdentifiers.h>
 
 namespace MultiplayerSample
 {
@@ -79,8 +80,9 @@ namespace MultiplayerSample
             auto ignoreEntitiesFilterCallback =
                 [&filter, networkEntityManager](const AzPhysics::SimulatedBody* body, [[maybe_unused]] const Physics::Shape* shape)
             {
-                // Exclude the bodies from another rewind frame
-                if ((filter.m_rewindFrameId != Multiplayer::InvalidHostFrameId)
+                // Exclude the dynamic bodies from another rewind frame
+                if (filter.m_rewindFrameId != Multiplayer::InvalidHostFrameId
+                    && body->GetNativeType() != PhysX::NativeTypeIdentifiers::RigidBodyStatic
                      && (body->GetFrameId() != static_cast<uint32_t>(filter.m_rewindFrameId)))
                 {
                     return AzPhysics::SceneQuery::QueryHitType::None;

+ 4 - 4
Gem/Code/Source/Weapons/WeaponGathers.cpp

@@ -109,14 +109,14 @@ namespace MultiplayerSample
 
         float currSegmentStartTime = inOutActiveShot.m_lifetimeSeconds;
         AZ::Vector3 currSegmentPosition = inOutActiveShot.m_initialTransform.GetTranslation() + (segmentStepOffset * currSegmentStartTime) + (gravity * 0.5f * currSegmentStartTime * currSegmentStartTime);
+        const AZ::Transform currSegTransform = AZ::Transform::CreateFromQuaternionAndTranslation(inOutActiveShot.m_initialTransform.GetRotation(), currSegmentPosition);
+
         for (uint32_t segment = 0; segment < bg_MultitraceNumTraceSegments; ++segment)
         {
             float nextSegmentStartTime = currSegmentStartTime + segmentTickSize;
             AZ::Vector3 travelDistance = (segmentStepOffset * nextSegmentStartTime); // Total distance our shot has traveled as of this cast, ignoring arc-length due to gravity
-            AZ::Vector3 nextSegmentPosition = inOutActiveShot.m_initialTransform.GetTranslation() + travelDistance + (gravity * 0.5f * nextSegmentStartTime * nextSegmentStartTime);
-
-            const AZ::Transform currSegTransform = AZ::Transform::CreateFromQuaternionAndTranslation(inOutActiveShot.m_initialTransform.GetRotation(), currSegmentPosition);
-            const AZ::Vector3   segSweep = nextSegmentPosition - currSegmentPosition;
+            AZ::Vector3 nextSegmentPosition = inOutActiveShot.m_initialTransform.GetTranslation() + travelDistance + (gravity * 0.5f * nextSegmentStartTime * nextSegmentStartTime);         
+            const AZ::Vector3 segSweep = nextSegmentPosition - currSegmentPosition;
 
             IntersectFilter filter(currSegTransform, segSweep, AzPhysics::SceneQuery::QueryType::StaticAndDynamic,
                 hitMultiple, collisionGroup, filteredNetEntityIds, gatherParams.GetCurrentShapeConfiguration());

+ 2 - 1
Gem/Code/Source/Weapons/WeaponTypes.h

@@ -205,7 +205,8 @@ namespace MultiplayerSample
     //! Structure containing details for a single fire event.
     struct FireParams
     {
-        AZ::Vector3 m_targetPosition = AZ::Vector3::CreateZero(); // Location of the activate event.
+        AZ::Vector3 m_sourcePosition = AZ::Vector3::CreateZero(); // Source location of the activate event
+        AZ::Vector3 m_targetPosition = AZ::Vector3::CreateZero(); // Target location of the activate event.
         Multiplayer::NetEntityId m_targetId = Multiplayer::InvalidNetEntityId; // Entity Id of the target (for homing weapons)
 
         bool operator!=(const FireParams& rhs) const;