diff --git a/Assets/Game1.unity b/Assets/Game1.unity index 65ba7c3..2d66335 100644 Binary files a/Assets/Game1.unity and b/Assets/Game1.unity differ 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 4c4ba6f..d84369a 100644 Binary files a/Assets/ShotSphere.prefab and b/Assets/ShotSphere.prefab differ diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index 637ae4f..aab0211 100644 Binary files a/ProjectSettings/EditorBuildSettings.asset and b/ProjectSettings/EditorBuildSettings.asset differ diff --git a/ProjectSettings/GraphicsSettings.asset b/ProjectSettings/GraphicsSettings.asset index 4794c37..9861984 100644 Binary files a/ProjectSettings/GraphicsSettings.asset and b/ProjectSettings/GraphicsSettings.asset differ diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 3dfda84..8e033b8 100644 Binary files a/ProjectSettings/ProjectSettings.asset and b/ProjectSettings/ProjectSettings.asset differ