Explorar o código

Small fixes to faceoff

Axel Nordh hai 3 meses
pai
achega
68009b1d70
Modificáronse 1 ficheiros con 16 adicións e 7 borrados
  1. 16 7
      Assets/Scripts/PuckController.cs

+ 16 - 7
Assets/Scripts/PuckController.cs

@@ -108,7 +108,8 @@ public class PuckController : MonoBehaviour
 
             transform.position = targetCarryPosition;
 
-            if (rb != null)
+            // Only set velocities if NOT kinematic
+            if (rb != null && !rb.isKinematic)
             {
                 rb.linearVelocity = Vector3.zero;
                 rb.angularVelocity = Vector3.zero;
@@ -129,7 +130,7 @@ public class PuckController : MonoBehaviour
                 pos.y = 0.025f;
                 transform.position = pos;
 
-                if (rb != null)
+                if (rb != null && !rb.isKinematic)
                 {
                     Vector3 vel = rb.linearVelocity;
                     if (vel.y < 0)
@@ -202,21 +203,28 @@ public class PuckController : MonoBehaviour
 
         currentCarrier = player;
         isBeingCarried = true;
+        isPassActive = false; // Stop pass when picked up
 
         if (player != null)
         {
             // IMPORTANT: Stop all physics movement immediately
             if (rb != null)
             {
-                rb.linearVelocity = Vector3.zero;
-                rb.angularVelocity = Vector3.zero;
-                rb.isKinematic = true; // Make kinematic while carried
+                // Stop velocities BEFORE making kinematic
+                if (!rb.isKinematic)
+                {
+                    rb.linearVelocity = Vector3.zero;
+                    rb.angularVelocity = Vector3.zero;
+                }
+
+                // Now make kinematic
+                rb.isKinematic = true;
             }
 
             // Position puck at player's feet immediately to prevent bouncing
             Vector3 playerForward = player.transform.forward;
             Vector3 targetPos = player.transform.position + playerForward * carrierOffset;
-            targetPos.y = 0.025f; // Puck height
+            targetPos.y = 0.025f;
             transform.position = targetPos;
 
             player.GainPuck(this);
@@ -235,9 +243,10 @@ public class PuckController : MonoBehaviour
         isBeingCarried = false;
 
         // Re-enable physics
-        if (rb != null)
+        if (rb != null && rb.isKinematic)
         {
             rb.isKinematic = false;
+            // Velocities will be set by ApplyForce or naturally by physics
         }
 
         UpdateVisualState(false);