From c7786a5b5609660b3495d80dffeb4d075ab37a30 Mon Sep 17 00:00:00 2001 From: JesusLuvsYooh <57072365+JesusLuvsYooh@users.noreply.github.com> Date: Fri, 2 Aug 2024 11:57:56 +0100 Subject: [PATCH] fix: Examples colliders and missing namespace. (#3881) * fix: Example scene and prefab colliders fixed. No idea what happened, but some box colliders seem to be double the default size. * Namespace to couch coop scripts. --- .../Examples/CouchCoop/MirrorCouchCoop.unity | 30 ++--- .../CouchCoop/Scripts/MovingPlatform.cs | 125 +++++++++--------- .../CouchCoop/Scripts/PlatformMovement.cs | 63 ++++----- .../TopDownShooter/Prefabs/EnemyPrefab.prefab | 2 +- 4 files changed, 113 insertions(+), 107 deletions(-) diff --git a/Assets/Mirror/Examples/CouchCoop/MirrorCouchCoop.unity b/Assets/Mirror/Examples/CouchCoop/MirrorCouchCoop.unity index ba404b206..762332381 100644 --- a/Assets/Mirror/Examples/CouchCoop/MirrorCouchCoop.unity +++ b/Assets/Mirror/Examples/CouchCoop/MirrorCouchCoop.unity @@ -165,7 +165,7 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 2, y: 2, z: 2} + m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} --- !u!23 &34377706 MeshRenderer: @@ -258,7 +258,7 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 2, y: 2, z: 2} + m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} --- !u!23 &80415369 MeshRenderer: @@ -497,7 +497,7 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 2, y: 2, z: 2} + m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} --- !u!23 &121552836 MeshRenderer: @@ -642,7 +642,7 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 2, y: 2, z: 2} + m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} --- !u!23 &388677688 MeshRenderer: @@ -792,7 +792,7 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 2, y: 2, z: 2} + m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} --- !u!23 &446496355 MeshRenderer: @@ -928,7 +928,7 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 2, y: 2, z: 2} + m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} --- !u!23 &498523325 MeshRenderer: @@ -1183,7 +1183,7 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 2, y: 2, z: 2} + m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} --- !u!23 &738449928 MeshRenderer: @@ -1319,7 +1319,7 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 2, y: 2, z: 2} + m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} --- !u!23 &828682888 MeshRenderer: @@ -1412,7 +1412,7 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 2, y: 2, z: 2} + m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} --- !u!23 &898358223 MeshRenderer: @@ -1697,7 +1697,7 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 2, y: 2, z: 2} + m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} --- !u!23 &1179387014 MeshRenderer: @@ -1829,7 +1829,7 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 2, y: 2, z: 2} + m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} --- !u!23 &1218169083 MeshRenderer: @@ -1922,7 +1922,7 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 2, y: 2, z: 2} + m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} --- !u!23 &1263590062 MeshRenderer: @@ -2091,7 +2091,7 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 2, y: 2, z: 2} + m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} --- !u!23 &1284513254 MeshRenderer: @@ -2565,7 +2565,7 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 2, y: 2, z: 2} + m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} --- !u!23 &1648326111 MeshRenderer: @@ -3174,7 +3174,7 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 2, y: 2, z: 2} + m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} --- !u!23 &2105958124 MeshRenderer: diff --git a/Assets/Mirror/Examples/CouchCoop/Scripts/MovingPlatform.cs b/Assets/Mirror/Examples/CouchCoop/Scripts/MovingPlatform.cs index 65b2a9657..32e7e51df 100644 --- a/Assets/Mirror/Examples/CouchCoop/Scripts/MovingPlatform.cs +++ b/Assets/Mirror/Examples/CouchCoop/Scripts/MovingPlatform.cs @@ -1,76 +1,79 @@ using UnityEngine; using Mirror; -public class MovingPlatform : NetworkBehaviour +namespace Mirror.Examples.CouchCoop { - public Transform endTarget; - public float moveSpeed = 0.5f; - // allows for on demand syncing of stopping and starting platform movement, change via server - // note,sync vars changed via inspector do not sync. This is optional feature, can be removed - [SyncVar] - public bool moveObj = true; - - // optional fancy features - public bool moveStopsUponExit = false; - public bool moveStartsUponCollision = false; - - private Vector3 startPosition; - private Vector3 endPosition; - - void Awake() + public class MovingPlatform : NetworkBehaviour { - startPosition = transform.position; - endPosition = endTarget.position; - } + public Transform endTarget; + public float moveSpeed = 0.5f; + // allows for on demand syncing of stopping and starting platform movement, change via server + // note,sync vars changed via inspector do not sync. This is optional feature, can be removed + [SyncVar] + public bool moveObj = true; - void Update() - { - if (moveObj) + // optional fancy features + public bool moveStopsUponExit = false; + public bool moveStartsUponCollision = false; + + private Vector3 startPosition; + private Vector3 endPosition; + + void Awake() { - float step = moveSpeed * Time.deltaTime; - transform.position = Vector3.MoveTowards(transform.position, endPosition, step); + startPosition = transform.position; + endPosition = endTarget.position; + } - if (Vector3.Distance(transform.position, endPosition) < 0.001f) + void Update() + { + if (moveObj) { - endPosition = endPosition == startPosition ? endTarget.position : startPosition; - if (isServer) + float step = moveSpeed * Time.deltaTime; + transform.position = Vector3.MoveTowards(transform.position, endPosition, step); + + if (Vector3.Distance(transform.position, endPosition) < 0.001f) { - RpcResyncPosition(endPosition == startPosition ? (byte)1 : (byte)0); + endPosition = endPosition == startPosition ? endTarget.position : startPosition; + if (isServer) + { + RpcResyncPosition(endPosition == startPosition ? (byte)1 : (byte)0); + } + } + } + } + + [ClientRpc] + void RpcResyncPosition(byte _value) + { + //print("RpcResyncPosition: " + _value); + transform.position = _value == 1 ? endTarget.position : startPosition; + } + + // optional + [ServerCallback] + private void OnCollisionEnter(Collision collision) + { + if (moveStartsUponCollision) + { + if (collision.gameObject.tag == "Player") + { + moveObj = true; + } + } + } + + // optional + [ServerCallback] + private void OnCollisionExit(Collision collision) + { + if (moveStopsUponExit) + { + if (collision.gameObject.tag == "Player") + { + moveObj = false; } } } } - - [ClientRpc] - void RpcResyncPosition(byte _value) - { - //print("RpcResyncPosition: " + _value); - transform.position = _value == 1 ? endTarget.position : startPosition; - } - - // optional - [ServerCallback] - private void OnCollisionEnter(Collision collision) - { - if (moveStartsUponCollision) - { - if (collision.gameObject.tag == "Player") - { - moveObj = true; - } - } - } - - // optional - [ServerCallback] - private void OnCollisionExit(Collision collision) - { - if (moveStopsUponExit) - { - if (collision.gameObject.tag == "Player") - { - moveObj = false; - } - } - } } \ No newline at end of file diff --git a/Assets/Mirror/Examples/CouchCoop/Scripts/PlatformMovement.cs b/Assets/Mirror/Examples/CouchCoop/Scripts/PlatformMovement.cs index 1bd14410f..a8db1a3c2 100644 --- a/Assets/Mirror/Examples/CouchCoop/Scripts/PlatformMovement.cs +++ b/Assets/Mirror/Examples/CouchCoop/Scripts/PlatformMovement.cs @@ -1,46 +1,49 @@ using UnityEngine; using Mirror; -public class PlatformMovement : NetworkBehaviour +namespace Mirror.Examples.CouchCoop { - // A separate script to handle platform behaviour, see its partner script, MovingPlatform.cs - private bool onPlatform; - private Transform platformTransform; - private Vector3 lastPlatformPosition; - - public override void OnStartAuthority() + public class PlatformMovement : NetworkBehaviour { - this.enabled = true; - } + // A separate script to handle platform behaviour, see its partner script, MovingPlatform.cs + private bool onPlatform; + private Transform platformTransform; + private Vector3 lastPlatformPosition; - void FixedUpdate() - { - if (onPlatform) + public override void OnStartAuthority() { - Vector3 deltaPosition = platformTransform.position - lastPlatformPosition; - transform.position += deltaPosition; - lastPlatformPosition = platformTransform.position; + this.enabled = true; } - } - private void OnCollisionEnter(Collision collision) - { - - if (collision.gameObject.tag == "Finish") + void FixedUpdate() { - platformTransform = collision.gameObject.GetComponent(); - lastPlatformPosition = platformTransform.position; - onPlatform = true; + if (onPlatform) + { + Vector3 deltaPosition = platformTransform.position - lastPlatformPosition; + transform.position += deltaPosition; + lastPlatformPosition = platformTransform.position; + } } - } - private void OnCollisionExit(Collision collision) - { - // ideally set a Platform tag, but we'l just use a Unity Pre-set. - if (collision.gameObject.tag == "Finish") + private void OnCollisionEnter(Collision collision) { - onPlatform = false; - platformTransform = null; + + if (collision.gameObject.tag == "Finish") + { + platformTransform = collision.gameObject.GetComponent(); + lastPlatformPosition = platformTransform.position; + onPlatform = true; + } + } + + private void OnCollisionExit(Collision collision) + { + // ideally set a Platform tag, but we'l just use a Unity Pre-set. + if (collision.gameObject.tag == "Finish") + { + onPlatform = false; + platformTransform = null; + } } } } diff --git a/Assets/Mirror/Examples/TopDownShooter/Prefabs/EnemyPrefab.prefab b/Assets/Mirror/Examples/TopDownShooter/Prefabs/EnemyPrefab.prefab index 303d8d2f3..ddce1ffe5 100644 --- a/Assets/Mirror/Examples/TopDownShooter/Prefabs/EnemyPrefab.prefab +++ b/Assets/Mirror/Examples/TopDownShooter/Prefabs/EnemyPrefab.prefab @@ -539,7 +539,7 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 2, y: 2, z: 2} + m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0.5, z: -0.1} --- !u!114 &4118329204170882586 MonoBehaviour: