From 1851785fc03ad1f725c2893eb16907481ba55d5b Mon Sep 17 00:00:00 2001 From: JWS Date: Sun, 30 Jan 2022 20:00:35 -0600 Subject: [PATCH] Levels are now work again, better color differentiation between players, initial client connect now properly enables the server player ship, orientation is still not right until the other player moves however. Currently just one rock per level for testing. PC back to windowed mode for debugging instead of screen and video capture. --- Assets/Game1.unity | Bin 29480 -> 30088 bytes Assets/Levels.cs | 7 ++ Assets/RockField1.prefab | Bin 8484 -> 8484 bytes Assets/RockField2.prefab | Bin 8484 -> 8484 bytes Assets/RockSphere.cs | 4 +- Assets/RockSphere1.prefab | Bin 19680 -> 19680 bytes Assets/RocketSphere.cs | 94 ++++++++++++++++++------- ProjectSettings/GraphicsSettings.asset | Bin 5540 -> 5528 bytes ProjectSettings/ProjectSettings.asset | Bin 72988 -> 72980 bytes 9 files changed, 78 insertions(+), 27 deletions(-) diff --git a/Assets/Game1.unity b/Assets/Game1.unity index c50531b3a518e47162bc5dce204cfd2071005ad4..731bdab37b2ea8b5744e04712fc0c5970d84f309 100644 GIT binary patch delta 920 zcmXw%OH30{6o&6@r={gt?X(32TZDuzP{6Qgq)`Zpm?#h{q!JTb=+FnHEiE8TFm$1j zMB?V)f{m6$6J6@KF)>l18x`G>m|J-}e-2cKCesBw8 z;U31O7Z_tUvVV9EAo3ie+dVbhN%a?; z+(lh@*HhP^Rk&1)hz{tWh_vGCJ(?L+63Xci%P8p?CEcHhXW2|N6CH^wY~oT^CZkN@ zVW6dHKeRDzVO^W9%BD*uG6;&%x$U8z6_qI`xcQL~VqsHI@g9pe})a%Qia#Gr?#Q zQTYAQSPq4_df{i=Y7iGX&rGPMk%>n8E@U~dIBFB*&{zSixcHmttp}gjEOya|XokLP zEDx4KT?!R6X2H%xUm4Wn$omkO2dq;!&saH%<`1s}0?xu|1yO9~u*O_)5+|;JS~Qje z^J8L_V67V4fcp|^ah+`%OToMqefaU%5sl?xR6K}@u8c-#PsqOaNzJ=AwafiWj~>+A z)TJy|J)_OhR%#0Q)mxz~SM6iNIxp^d=P3?I6vZKkyf`G0i({QpW|a8ZU?Lb+(ln45 zki@hp5NqaepRm%abcccMutKzv))JoG2Ftihde&iWr`5DqO+^+tJx)~9&qx_LW7{Mr zt0@&VsowFsI&OeZH+d7YG?kRe5|gMo*-L9FSzSn;;1rsa>2vBT$r+iRhD~a2vYk_H M)Fg=$Q2m(eKlHfP2mk;8 delta 650 zcmXw#O=uHQ6ov0gCVy>WM@X7r3l`Ev7SW~#afDQhEs}!JLJ_K{SlYC4@`IDag;+^J zg)AynZZL%5`Ka>Fg$vVEq< z7cXI%Jfyw5e|XIIWvj6g%}(DcytQ7Lx%{$gpnm(ssp}tG<2{%fk}I(pCpV{uT=r6k zoinGae}bWII~fil3$8)iiZ#J%$o6<>BN~N~;Uu~Ox97SQYl7vG-B4JuJ`C*cZhGGv zcts7cez*tv_McVh1K?!cDe+y>-!M4K%%kqk;}7 zmPOGyYT0pk{Oj5B` zunAJ%@^f^838Ta1!MpK delta 14 VcmZ4Dw8Uw{1$joU%@^f^838UB1#SQU diff --git a/Assets/RockField2.prefab b/Assets/RockField2.prefab index c2589a0519c8509481db5d571e6cb880f38a0a8e..58258793ce9e97e8dddd5e8057eadb4cdc33aa8d 100644 GIT binary patch delta 14 VcmZ4Dw8Uw{1$jos%@^f^838Tg1!VvL delta 14 VcmZ4Dw8Uw{1$joU%@^f^838UB1#SQU diff --git a/Assets/RockSphere.cs b/Assets/RockSphere.cs index 64dad71..ba69c63 100644 --- a/Assets/RockSphere.cs +++ b/Assets/RockSphere.cs @@ -86,7 +86,8 @@ void Start() } count++; - } + Debug.Log("Add Rocks " + count + " " + Random.Range(0.0f, 1.0f).ToString()); + } [ServerCallback] void OnTriggerEnter(Collider other) @@ -99,6 +100,7 @@ void OnTriggerEnter(Collider other) destroyed = true; NetworkServer.Destroy(transform.gameObject); count--; + Debug.Log("Destroy Rocks " + count + " " + Random.Range(0.0f, 1.0f).ToString()); if (rockSpherePrefab) { diff --git a/Assets/RockSphere1.prefab b/Assets/RockSphere1.prefab index 93e420cc614c3e04e24acac9615a6dccb71aca34..705b1a43522ec37d5aa3e3cbf6eeca56c2f19f2b 100644 GIT binary patch delta 18 acmaDblkve!#tjj!lbf7PHut!Oumb>5#Rshb delta 20 ccmaDblkve!#tjj!j7*aoosBp5xQ4I;09slHt^fc4 diff --git a/Assets/RocketSphere.cs b/Assets/RocketSphere.cs index 9138079..8b4458c 100644 --- a/Assets/RocketSphere.cs +++ b/Assets/RocketSphere.cs @@ -41,9 +41,13 @@ public class RocketSphere : NetworkBehaviour AudioSource hyperspaceSound; AudioSource engineSound; public GameObject explosionPrefab; - public GameObject spawnPrefab; Rigidbody rb; [SyncVar] Color RocketColor = Color.white; + [SyncVar] float hue = 0.0f; + [SyncVar] bool visible = false; + // [SyncVar] Vector3 posSave = Vector3.zero; + // [SyncVar] Quaternion rotSave = Quaternion.identity; + [SyncVar] Quaternion rot2Save = Quaternion.identity; // Unity makes a clone of the Material every time GetComponent().material is used. // Cache it here and Destroy it in OnDestroy to prevent a memory leak. @@ -60,30 +64,38 @@ public override void OnStartServer() base.OnStartServer(); // create a random color for each player as they are created on the server - RocketColor = new Color(Random.Range(0.3f, 1.0f), Random.Range(0.3f, 1.0f), Random.Range(0.3f, 1.0f)); + //RocketColor = new Color(Random.Range(0.3f, 1.0f), Random.Range(0.3f, 1.0f), Random.Range(0.3f, 1.0f)); + + float hue = Random.Range(0.0f, 1.0f); + + RocketSphere[] players = FindObjectsOfType(); + + for (int i = 0; i < players.Length; i++) + { + // check for difference between player and chosen hue, + // difference check must be small enough that we have enough colors for all players. + // if max player count is increased from 4, this value should be reassessed + // this could be an infinte check otherwise, might want a failsafe escape + if (Mathf.Abs(hue - players[i].hue) < 0.1f) + { + // generate a new hue if it is too close to this other players color + hue = Random.Range(0.0f, 1.0f); + + // restart check with new hue until we find a hue that is different enough from all the other players. + i = 0; + } + } + + // rocket color is now set for this player until it is destroyed + RocketColor = Color.HSVToRGB(hue, 1.0f, 1.0f); } // Use this for initialization void Start() { - // get the current radius from position - //float radius = transform.position.magnitude; - //Vector3 pos = transform.position; - - //reset the position back to the center - transform.position = Vector3.zero; - transform.rotation = Quaternion.identity; - - // Move rocket child gameobject out to radius - Vector3 pos = Vector3.forward * radius; - Quaternion rot = Quaternion.FromToRotation(Vector3.forward, pos); - // Find the rocket child object rocket = transform.Find("Rocket").gameObject; - rocket.transform.position = pos; - rocket.transform.rotation = rot; - // find the engine child object and attach the particle generator GameObject engine = transform.Find("Rocket").Find("Engine").gameObject; engineParticleSystem = engine.GetComponent(); @@ -95,6 +107,14 @@ void Start() // find the rb so we can apply torque during the Update() rb = transform.GetComponent(); + //reset the position back to the center + transform.position = Vector3.zero; + transform.rotation = Quaternion.identity; + + // Move rocket child gameobject out to radius + rocket.transform.position = Vector3.forward * radius; + rocket.transform.rotation = Quaternion.FromToRotation(Vector3.forward, rocket.transform.position); ; + // Keep the player objects through level changes DontDestroyOnLoad(this); @@ -107,8 +127,20 @@ void Start() cachedMaterial = rocket.GetComponent().material; cachedMaterial.color = RocketColor; - // spawn the ship on the server - CmdSpawnShipDelay(); + if (isLocalPlayer) + { + // spawn the ship on the client in the direction the player is currently looking after 5 seconds + // which will enable the ship and then enable it on the other player clients through the server + Invoke("SpawnShip", 5); + } + else + { + // not our rocket so we need to update the state based on the server sync var state + rocket.SetActive(visible); + //rocket.transform.position = posSave; + //rocket.transform.rotation = rotSave; + transform.rotation = rot2Save; + } } private void OnLevelWasLoaded(int level) @@ -130,17 +162,21 @@ void MySetActive(bool active, Quaternion rotation) // make the rocket invisible rocket.SetActive(false); + visible = false; } else { - // put initial rotation of new spacecraft at current camera rotation so player can orient spawn position to a safe spot + // put initial rotation of new spacecraft at current camera rotation so player can orient spawn position to a safe spot, + // save it so new players know where to create the ship, if the player doesn't move transform.rotation = rotation; + rot2Save = rotation; // restart rb movement rb.isKinematic = false; // make the rocket visible again rocket.SetActive(true); + visible = true; // play the hyperspace sound on enable hyperspaceSound.Play(); @@ -159,12 +195,6 @@ void CmdMySetActive(bool active, Quaternion rotation) RpcMySetActive(active, rotation); } - [Command] - void CmdSpawnShipDelay() - { - rpcSpawnShipDelay(); - } - [Client] void SpawnShip() { @@ -339,6 +369,12 @@ void CmdHyperspace() void Update() { + // make sure the state matches the server state + if (visible != rocket.activeSelf) + { + rocket.SetActive(visible); + } + // only allow input for local player if (!isLocalPlayer) return; @@ -382,5 +418,11 @@ void Update() { CmdHyperspace(); } + + if (Input.GetButtonDown("Submit")) + { + + } + } } \ No newline at end of file diff --git a/ProjectSettings/GraphicsSettings.asset b/ProjectSettings/GraphicsSettings.asset index 9861984a752be30a740c2c5d7e930ae86ef0d8cd..4794c37a03dbac71db4a0fafa0a9d2f81291930e 100644 GIT binary patch delta 33 pcmZ3YJwuy=fk8xrfkAY}Mvgbaj1iN+3ZG}>ntW8Gda{pb1OS`p3OxV- delta 40 wcmbQCy+oUXfk8xrfkAZ1Mvgbaj46}93ZG}>o_tiKnvIcxfuY%MvXy8Y0O2zW5&!@I diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index e2ec52579c9a053f295189ac26ab3ebf45457296..e5233de988a3b90cb6bf7465889573d9bbd15534 100644 GIT binary patch delta 57 zcmbQUi)G3#76ArEmRtr#SrG;X22mh;LZiS|0mc{>rWT3m2iX|amTzHUWMWj?9>~vl MnQ?mo2jdzM0Bi0IN&o-= delta 133 zcmbQTi)GF(76ArEmYEEUvN8+|45C2xhDL#{0*o;%7C90?5h!2+(TkZg*|`^%J9pSR$3<&c#^nyTkSWChqCK-ZE`(VPOBMZN&y70N> YCuci=v^acTJH3#FQF40*2jdzM0HUxVD*ylh