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.
This commit is contained in:
JesusLuvsYooh 2024-08-02 11:57:56 +01:00 committed by GitHub
parent b409245946
commit 5b7da43d5c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 113 additions and 107 deletions

View File

@ -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:

View File

@ -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;
}
}
}
}

View File

@ -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<Transform>();
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<Transform>();
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;
}
}
}
}

View File

@ -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: