From f203b6d7109fd989482d6d7ecef75258e38a7655 Mon Sep 17 00:00:00 2001 From: BOTAlex Date: Wed, 28 Feb 2024 18:59:39 +0100 Subject: [PATCH] Started server-sided rope --- Assets/Scenes/GameScene.unity | 18 +++++++++++++++--- .../Scripts/Rope/Project.Scripts.Rope.asmdef | 4 +++- Assets/Scripts/Rope/RopeSimulator.cs | 13 +++++++++---- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Assets/Scenes/GameScene.unity b/Assets/Scenes/GameScene.unity index 2e170ce..42054c6 100644 --- a/Assets/Scenes/GameScene.unity +++ b/Assets/Scenes/GameScene.unity @@ -3669,7 +3669,10 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] - m_AddedGameObjects: [] + m_AddedGameObjects: + - targetCorrespondingSourceObject: {fileID: 3032075919872812610, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3} + insertIndex: -1 + addedObject: {fileID: 4910321061857220296} m_AddedComponents: - targetCorrespondingSourceObject: {fileID: 809911508645467208, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3} insertIndex: -1 @@ -3678,6 +3681,11 @@ PrefabInstance: insertIndex: -1 addedObject: {fileID: 1683288374126251330} m_SourcePrefab: {fileID: 100100000, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3} +--- !u!4 &1683288374126251322 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 3032075919872812610, guid: ec5007446d8bbca48bf02b3a7e752da1, type: 3} + m_PrefabInstance: {fileID: 1683288374126251321} + m_PrefabAsset: {fileID: 0} --- !u!114 &1683288374126251323 MonoBehaviour: m_ObjectHideFlags: 0 @@ -3834,7 +3842,7 @@ PrefabInstance: serializedVersion: 2 m_Modification: serializedVersion: 3 - m_TransformParent: {fileID: 0} + m_TransformParent: {fileID: 1683288374126251322} m_Modifications: - target: {fileID: 144529238244638330, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3} propertyPath: m_LocalPosition.x @@ -3885,6 +3893,11 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3} +--- !u!4 &4910321061857220296 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 144529238244638330, guid: 0248db69242a3dd47898c6742b6c9f60, type: 3} + m_PrefabInstance: {fileID: 4910321061857220295} + m_PrefabAsset: {fileID: 0} --- !u!1001 &5796191506433166633 PrefabInstance: m_ObjectHideFlags: 0 @@ -4763,7 +4776,6 @@ PrefabInstance: SceneRoots: m_ObjectHideFlags: 0 m_Roots: - - {fileID: 4910321061857220295} - {fileID: 1683288374126251321} - {fileID: 1536317696} - {fileID: 4158834148864819266} diff --git a/Assets/Scripts/Rope/Project.Scripts.Rope.asmdef b/Assets/Scripts/Rope/Project.Scripts.Rope.asmdef index b00a2d7..ffa4845 100644 --- a/Assets/Scripts/Rope/Project.Scripts.Rope.asmdef +++ b/Assets/Scripts/Rope/Project.Scripts.Rope.asmdef @@ -6,7 +6,9 @@ "GUID:6055be8ebefd69e48b49212b09b47b2f", "GUID:f4c364e1215051e4dbc6c0bc8fb49793", "GUID:ddd4dba7c768b564a879069c52854fc5", - "GUID:c0e1b40f519e6e84b8f4af9930403ecb" + "GUID:c0e1b40f519e6e84b8f4af9930403ecb", + "GUID:3b8ed52f1b5c64994af4c4e0aa4b6c4b", + "GUID:1491147abca9d7d4bb7105af628b223e" ], "includePlatforms": [], "excludePlatforms": [], diff --git a/Assets/Scripts/Rope/RopeSimulator.cs b/Assets/Scripts/Rope/RopeSimulator.cs index db2c913..9cb4acb 100644 --- a/Assets/Scripts/Rope/RopeSimulator.cs +++ b/Assets/Scripts/Rope/RopeSimulator.cs @@ -2,10 +2,11 @@ using System; using System.Collections; using System.Collections.Generic; using System.Linq; +using Unity.Netcode; using UnityEngine; using UnityEngine.Assertions; -public class RopeSimulator : MonoBehaviour +public class RopeSimulator : NetworkBehaviour { [SerializeField] private float gravity = 10; @@ -246,7 +247,7 @@ public class RopeSimulator : MonoBehaviour // Benjamin forgor... to assign if (ropeCollidersParent == null) { - var holder = new GameObject("RopeHolder"); + var holder = new GameObject("RopeColiderHolder"); ropeCollidersParent = holder.transform; } @@ -263,8 +264,12 @@ public class RopeSimulator : MonoBehaviour ropeCollider.transform.position = point.position; ropeCollider.layer = LayerMask.NameToLayer("Rope"); - var colliderComponent = ropeCollider.AddComponent(); - colliderComponent.radius = ropeRadius; + if (!IsClient) // Only coliders for the server/host + { + var colliderComponent = ropeCollider.AddComponent(); + colliderComponent.radius = ropeRadius; + } + var rigidBody = ropeCollider.AddComponent(); rigidBody.isKinematic = true;