From 989df42172b7405ab5cea9143617996a65ef2c3d Mon Sep 17 00:00:00 2001 From: JWS Date: Wed, 2 Feb 2022 21:14:17 -0600 Subject: [PATCH] Player shots will not hit the player now. --- Assets/Game1.unity | Bin 28540 -> 28540 bytes Assets/RocketSphere.cs | 18 ++++++++++++++++-- Assets/ShotSphere.cs | 12 ++++++++++++ Assets/ShotSphere.prefab | Bin 23268 -> 23268 bytes ProjectSettings/EditorBuildSettings.asset | Bin 4336 -> 4336 bytes ProjectSettings/GraphicsSettings.asset | Bin 5528 -> 5540 bytes ProjectSettings/ProjectSettings.asset | Bin 73312 -> 73396 bytes 7 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Assets/Game1.unity b/Assets/Game1.unity index 65ba7c3d6b2ccf6496cdcdc374c69e91a29626e4..2d663353db7c8f58e4504538f00073b8ce68506c 100644 GIT binary patch delta 16 Xcmex!kMYkv#tlAsj3S$T^Yj@3NA?EP delta 16 Xcmex!kMYkv#tlAsj4Ydd^Yj@3N0tV} diff --git a/Assets/RocketSphere.cs b/Assets/RocketSphere.cs index 3715f2e..e4550c6 100644 --- a/Assets/RocketSphere.cs +++ b/Assets/RocketSphere.cs @@ -40,7 +40,7 @@ public class RocketSphere : NetworkBehaviour public GameObject explosionPrefab; Rigidbody rb; [SyncVar] Color RocketColor = Color.white; - float hue = 2.0f; + public float hue = 2.0f; [SyncVar] bool visible = false; [SyncVar] Quaternion rot2Save = Quaternion.identity; @@ -292,6 +292,17 @@ void OnTriggerEnter(Collider other) // Rocket is already destroyed, ignore if (!rocket.activeSelf) return; + ShotSphere shot = other.attachedRigidbody.GetComponent(); + + if (shot) + { + if (shot.playershooterhue == hue) + { + // ignore our own shots + return; + } + } + // Spawn an explosion at player position on all clients GameObject explosion = Instantiate(explosionPrefab, rocket.transform.position, Quaternion.identity) as GameObject; NetworkServer.Spawn(explosion); @@ -315,8 +326,11 @@ void Fire() GameObject shot = Instantiate(shotPrefab, pos, rot) as GameObject; - shot.transform.rotation = transform.rotation; + // save the hue of the shooter in the shot so we won't collide with it later + shot.GetComponent().playershooterhue = hue; + shot.transform.rotation = transform.rotation; + Rigidbody rbshot = shot.GetComponent(); rbshot.angularVelocity = rb.angularVelocity; diff --git a/Assets/ShotSphere.cs b/Assets/ShotSphere.cs index d26d674..a942caa 100644 --- a/Assets/ShotSphere.cs +++ b/Assets/ShotSphere.cs @@ -9,6 +9,7 @@ public class ShotSphere : NetworkBehaviour public GameObject shotPrefab; GameObject shot; public GameObject explosionPrefab; + public float playershooterhue = -10.0f; bool destroyed = false; public override void OnStartServer() @@ -42,6 +43,17 @@ void Start() [ServerCallback] void OnTriggerEnter(Collider other) { + RocketSphere rocket = other.attachedRigidbody.GetComponent(); + + if (rocket) + { + if (rocket.hue == playershooterhue) + { + // ignore our own shots + return; + } + } + if (destroyed == false) { destroyed = true; diff --git a/Assets/ShotSphere.prefab b/Assets/ShotSphere.prefab index 4c4ba6f603499ac1b18735b9f76ebb015fae5538..d84369a72b563d91fa52cbdfd2513142ca34edc8 100644 GIT binary patch delta 16 YcmaE|mGQ||#tm;G7#TLdjrh(807)?j8UO$Q delta 18 acmaE|mGQ||#tm;GCfkH_Z2l7Qfe`>*CJ9FX diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index 637ae4fcf5635af77ef4306d06a4e9b8a1f05b39..aab02118a626c2da4adc36ef11b74da6e3fdac65 100644 GIT binary patch delta 29 lcmeyM_(5@lD~rGqsT_AM#&X{suKzc2Pyh9Hb12Jf9ssj@3|0UD delta 29 lcmeyM_(5@lD~o`|>5%9XlFQr|FW%0@bUmeEb12Jf9ss>m3?l#l diff --git a/ProjectSettings/GraphicsSettings.asset b/ProjectSettings/GraphicsSettings.asset index 4794c37a03dbac71db4a0fafa0a9d2f81291930e..9861984a752be30a740c2c5d7e930ae86ef0d8cd 100644 GIT binary patch delta 40 wcmbQCy+oUXfk8xrfkAZ1Mvgbaj46}93ZG}>o_tiKnvIcxfuY%MvXy8Y0O2zW5&!@I delta 33 pcmZ3YJwuy=fk8xrfkAY}Mvgbaj1iN+3ZG}>ntW8Gda{pb1OS`p3OxV- diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 3dfda84da151db63c719b7c504daeedd6a4ad9c8..8e033b85e4c8b49579273e92742761c9c3ba2777 100644 GIT binary patch delta 148 zcmaE`hh@uN77hkRmYEEUa$6cXwsJ70u$Z$*F~9*6h_#qGlbw5ExpQ~^aUqZ1Iox1D zh9y!t?p%!JzB^q1Z{nW*>+SZ%ER4KNtY$zBZrcyCF&<}{eu0fKVH!6h3%{wl@VVtD nXFGs&I(%L`9VjiieG4a}1tTNd_P1P&YZ)0Cx6kHbJSqqPz#}KV delta 144 zcmdn8m*v4877hkRmYEEUatVzbTR9k0Sj;y_GQa^7h?TI{v32ofNtec3i#$FB8Crq` z87xkRM4ymc=Dv9Gb}pvtDGl2fvoP{9v6=!k*l$0`#(0@&x&jv?3%`dlkC|Dj%rB5G ihtF%L1EnOlb8s