From f144c4ffc815392e6823e54617a0b6a6ce0b76cf Mon Sep 17 00:00:00 2001 From: JesusLuvsYooh Date: Mon, 1 Jul 2024 19:54:19 +0100 Subject: [PATCH] Pickup Party Physics, part 4. A continuation and fix of last checkpoint. Pickups, movement, dropping, all working across multi players. Next part is map/game mode. --- .../Prefabs/PickupObject.prefab | 71 ++++++++++++ .../Prefabs/PlayerPrefab.prefab | 82 +++++++------- .../Scenes/MirrorPhysicsPickupParty.unity | 37 +++++- .../Scripts/PickupObject.cs | 12 ++ .../Scripts/PickupObject.cs.meta | 11 ++ .../Scripts/PlayerArmSlot.cs | 106 ++++++++++++++++-- .../Scripts/PlayerPickupParty.cs | 34 ++---- 7 files changed, 282 insertions(+), 71 deletions(-) create mode 100644 Assets/Mirror/Examples/PickupPartyPhysics/Scripts/PickupObject.cs create mode 100644 Assets/Mirror/Examples/PickupPartyPhysics/Scripts/PickupObject.cs.meta diff --git a/Assets/Mirror/Examples/PickupPartyPhysics/Prefabs/PickupObject.prefab b/Assets/Mirror/Examples/PickupPartyPhysics/Prefabs/PickupObject.prefab index 8c42705de..71bc2341d 100644 --- a/Assets/Mirror/Examples/PickupPartyPhysics/Prefabs/PickupObject.prefab +++ b/Assets/Mirror/Examples/PickupPartyPhysics/Prefabs/PickupObject.prefab @@ -13,6 +13,9 @@ GameObject: - component: {fileID: 7067323468124357061} - component: {fileID: 4167309113991024219} - component: {fileID: 1373717341218114730} + - component: {fileID: 3800001110859265949} + - component: {fileID: -3308771739656446756} + - component: {fileID: -337159362936431399} m_Layer: 0 m_Name: PickupObject m_TagString: Untagged @@ -133,3 +136,71 @@ Rigidbody: m_Interpolate: 0 m_Constraints: 0 m_CollisionDetection: 1 +--- !u!114 &3800001110859265949 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3350161566424659706} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: a553cb17010b2403e8523b558bffbc14, type: 3} + m_Name: + m_EditorClassIdentifier: + syncDirection: 0 + syncMode: 0 + syncInterval: 0 + target: {fileID: 1357295079658837445} + syncPosition: 1 + syncRotation: 1 + syncScale: 0 + onlySyncOnChange: 1 + compressRotation: 1 + interpolatePosition: 1 + interpolateRotation: 1 + interpolateScale: 0 + coordinateSpace: 0 + sendIntervalMultiplier: 3 + timelineOffset: 0 + showGizmos: 0 + showOverlay: 0 + overlayColor: {r: 0, g: 0, b: 0, a: 0.5} + bufferResetMultiplier: 3 + changedDetection: 1 + positionSensitivity: 0.01 + rotationSensitivity: 0.01 + scaleSensitivity: 0.01 +--- !u!114 &-3308771739656446756 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3350161566424659706} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9b91ecbcc199f4492b9a91e820070131, type: 3} + m_Name: + m_EditorClassIdentifier: + sceneId: 0 + _assetId: 1184563065 + serverOnly: 0 + visibility: 0 + hasSpawned: 0 +--- !u!114 &-337159362936431399 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3350161566424659706} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d95a3d991242d4718977902608114040, type: 3} + m_Name: + m_EditorClassIdentifier: + pickupRigidbody: {fileID: 1373717341218114730} + pickupCollider: {fileID: 4167309113991024219} + networkTransform: {fileID: 3800001110859265949} + playerHolder: {fileID: 0} diff --git a/Assets/Mirror/Examples/PickupPartyPhysics/Prefabs/PlayerPrefab.prefab b/Assets/Mirror/Examples/PickupPartyPhysics/Prefabs/PlayerPrefab.prefab index ed3b6922a..db37b8868 100644 --- a/Assets/Mirror/Examples/PickupPartyPhysics/Prefabs/PlayerPrefab.prefab +++ b/Assets/Mirror/Examples/PickupPartyPhysics/Prefabs/PlayerPrefab.prefab @@ -12,7 +12,7 @@ GameObject: - component: {fileID: 3478348578570543948} - component: {fileID: 3658412548173300767} m_Layer: 0 - m_Name: PlayerEye L + m_Name: PlayerEye 2 m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -96,7 +96,7 @@ GameObject: - component: {fileID: 3829460655408399729} - component: {fileID: 5820231610708102091} m_Layer: 0 - m_Name: PlayerEye R + m_Name: PlayerEye 1 m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -182,7 +182,7 @@ GameObject: - component: {fileID: 2237103095908280011} - component: {fileID: 1009485556880835443} m_Layer: 0 - m_Name: ArmSlotCollider L + m_Name: ArmSlotCollider 2 m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -197,8 +197,8 @@ Transform: m_GameObject: {fileID: 723173361404745613} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0.005, z: 1.85} - m_LocalScale: {x: 0.25, y: 0.25, z: 0.5727867} + m_LocalPosition: {x: 0, y: 0.005, z: 2} + m_LocalScale: {x: 0.35, y: 0.35, z: 0.5727867} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 6299839938573537759} @@ -270,7 +270,7 @@ BoxCollider: m_LayerOverridePriority: 0 m_IsTrigger: 1 m_ProvidesContacts: 0 - m_Enabled: 1 + m_Enabled: 0 serializedVersion: 3 m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} @@ -286,9 +286,14 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: aaee09512f5224b5598c70bd776912b7, type: 3} m_Name: m_EditorClassIdentifier: + syncDirection: 0 + syncMode: 0 + syncInterval: 0 playerPickupParty: {fileID: 6283092024802340800} - triggerCollider: {fileID: 2237103095908280011} + armTrigger: {fileID: 2237103095908280011} + pickedUpRigidbody: {fileID: 0} collidedGameObject: {fileID: 0} + pickedUpNetworkObject: {fileID: 0} --- !u!1 &931337917895386524 GameObject: m_ObjectHideFlags: 0 @@ -611,7 +616,7 @@ GameObject: - component: {fileID: 6299839938573537759} - component: {fileID: 1325586932094605749} m_Layer: 0 - m_Name: PlayerArmPivotL + m_Name: PlayerArmPivot2 m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -655,7 +660,7 @@ MonoBehaviour: syncScale: 0 onlySyncOnChange: 1 compressRotation: 1 - interpolatePosition: 1 + interpolatePosition: 0 interpolateRotation: 1 interpolateScale: 0 coordinateSpace: 0 @@ -886,19 +891,13 @@ MonoBehaviour: gravity: 40 armRotationSpeed: 50 canPickup: 0 - pickedUpObjects: - - {fileID: 0} - - {fileID: 0} - pickedUpRigidbodies: - - {fileID: 0} - - {fileID: 0} armPivots: - {fileID: 2672433250560454} - {fileID: 6299839938573537759} playerArmSlots: - {fileID: 3397797976900785828} - {fileID: 1009485556880835443} - freezePositionRB: 1 + freezeRotationRB: 1 characterController: {fileID: 4117093369808553598} --- !u!1 &5473584597135620801 GameObject: @@ -1077,10 +1076,10 @@ GameObject: - component: {fileID: 6532467146160453607} - component: {fileID: 8544325029674056831} - component: {fileID: 6490762623754511389} - - component: {fileID: 1508319704737576609} - component: {fileID: 3397797976900785828} + - component: {fileID: 1508319704737576609} m_Layer: 0 - m_Name: ArmSlotCollider R + m_Name: ArmSlotCollider 1 m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -1095,8 +1094,8 @@ Transform: m_GameObject: {fileID: 7317027042101436788} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0.005, z: 1.85} - m_LocalScale: {x: 0.25, y: 0.25, z: 0.5727868} + m_LocalPosition: {x: 0, y: 0.005, z: 2} + m_LocalScale: {x: 0.35, y: 0.35, z: 0.5727868} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 2672433250560454} @@ -1151,6 +1150,26 @@ MeshRenderer: m_SortingLayer: 0 m_SortingOrder: 0 m_AdditionalVertexStreams: {fileID: 0} +--- !u!114 &3397797976900785828 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7317027042101436788} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: aaee09512f5224b5598c70bd776912b7, type: 3} + m_Name: + m_EditorClassIdentifier: + syncDirection: 0 + syncMode: 0 + syncInterval: 0 + playerPickupParty: {fileID: 6283092024802340800} + armTrigger: {fileID: 1508319704737576609} + pickedUpRigidbody: {fileID: 0} + collidedGameObject: {fileID: 0} + pickedUpNetworkObject: {fileID: 0} --- !u!65 &1508319704737576609 BoxCollider: m_ObjectHideFlags: 0 @@ -1168,25 +1187,10 @@ BoxCollider: m_LayerOverridePriority: 0 m_IsTrigger: 1 m_ProvidesContacts: 0 - m_Enabled: 1 + m_Enabled: 0 serializedVersion: 3 m_Size: {x: 1, y: 1, z: 1} m_Center: {x: 0, y: 0, z: 0} ---- !u!114 &3397797976900785828 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7317027042101436788} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: aaee09512f5224b5598c70bd776912b7, type: 3} - m_Name: - m_EditorClassIdentifier: - playerPickupParty: {fileID: 6283092024802340800} - triggerCollider: {fileID: 1508319704737576609} - collidedGameObject: {fileID: 0} --- !u!1 &8085302157987762566 GameObject: m_ObjectHideFlags: 0 @@ -1198,7 +1202,7 @@ GameObject: - component: {fileID: 2672433250560454} - component: {fileID: 7204149903870050621} m_Layer: 0 - m_Name: PlayerArmPivotR + m_Name: PlayerArmPivot1 m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -1242,7 +1246,7 @@ MonoBehaviour: syncScale: 0 onlySyncOnChange: 1 compressRotation: 1 - interpolatePosition: 1 + interpolatePosition: 0 interpolateRotation: 1 interpolateScale: 0 coordinateSpace: 0 @@ -1362,4 +1366,4 @@ CapsuleCollider: m_Radius: 0.5000001 m_Height: 2 m_Direction: 1 - m_Center: {x: 0.000000059604645, y: 0, z: -0.00000008940697} + m_Center: {x: 0.00000005960464, y: 0, z: -0.00000008940697} diff --git a/Assets/Mirror/Examples/PickupPartyPhysics/Scenes/MirrorPhysicsPickupParty.unity b/Assets/Mirror/Examples/PickupPartyPhysics/Scenes/MirrorPhysicsPickupParty.unity index 9f2ef535c..3f87e48b9 100644 --- a/Assets/Mirror/Examples/PickupPartyPhysics/Scenes/MirrorPhysicsPickupParty.unity +++ b/Assets/Mirror/Examples/PickupPartyPhysics/Scenes/MirrorPhysicsPickupParty.unity @@ -239,6 +239,11 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1848308843} m_Modifications: + - target: {fileID: -3308771739656446756, guid: ab3b3f71325c24893869dd9f6c9bf556, + type: 3} + propertyPath: sceneId + value: 2743484708 + objectReference: {fileID: 0} - target: {fileID: 1357295079658837445, guid: ab3b3f71325c24893869dd9f6c9bf556, type: 3} propertyPath: m_LocalPosition.x @@ -318,6 +323,11 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1848308843} m_Modifications: + - target: {fileID: -3308771739656446756, guid: ab3b3f71325c24893869dd9f6c9bf556, + type: 3} + propertyPath: sceneId + value: 2669826224 + objectReference: {fileID: 0} - target: {fileID: 1357295079658837445, guid: ab3b3f71325c24893869dd9f6c9bf556, type: 3} propertyPath: m_LocalPosition.x @@ -430,6 +440,11 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1848308843} m_Modifications: + - target: {fileID: -3308771739656446756, guid: ab3b3f71325c24893869dd9f6c9bf556, + type: 3} + propertyPath: sceneId + value: 2802695346 + objectReference: {fileID: 0} - target: {fileID: 1357295079658837445, guid: ab3b3f71325c24893869dd9f6c9bf556, type: 3} propertyPath: m_LocalPosition.x @@ -987,6 +1002,11 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1848308843} m_Modifications: + - target: {fileID: -3308771739656446756, guid: ab3b3f71325c24893869dd9f6c9bf556, + type: 3} + propertyPath: sceneId + value: 479869901 + objectReference: {fileID: 0} - target: {fileID: 1357295079658837445, guid: ab3b3f71325c24893869dd9f6c9bf556, type: 3} propertyPath: m_LocalPosition.x @@ -1066,6 +1086,11 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1848308843} m_Modifications: + - target: {fileID: -3308771739656446756, guid: ab3b3f71325c24893869dd9f6c9bf556, + type: 3} + propertyPath: sceneId + value: 1228099150 + objectReference: {fileID: 0} - target: {fileID: 1357295079658837445, guid: ab3b3f71325c24893869dd9f6c9bf556, type: 3} propertyPath: m_LocalPosition.x @@ -1151,6 +1176,11 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1848308843} m_Modifications: + - target: {fileID: -3308771739656446756, guid: ab3b3f71325c24893869dd9f6c9bf556, + type: 3} + propertyPath: sceneId + value: 529400621 + objectReference: {fileID: 0} - target: {fileID: 1357295079658837445, guid: ab3b3f71325c24893869dd9f6c9bf556, type: 3} propertyPath: m_LocalPosition.x @@ -1305,6 +1335,11 @@ PrefabInstance: serializedVersion: 3 m_TransformParent: {fileID: 1848308843} m_Modifications: + - target: {fileID: -3308771739656446756, guid: ab3b3f71325c24893869dd9f6c9bf556, + type: 3} + propertyPath: sceneId + value: 3900675070 + objectReference: {fileID: 0} - target: {fileID: 1357295079658837445, guid: ab3b3f71325c24893869dd9f6c9bf556, type: 3} propertyPath: m_LocalPosition.x @@ -1406,7 +1441,7 @@ Transform: m_GameObject: {fileID: 4813915388203065815} serializedVersion: 2 m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalPosition: {x: -3.17, y: 0, z: 3.29} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: [] diff --git a/Assets/Mirror/Examples/PickupPartyPhysics/Scripts/PickupObject.cs b/Assets/Mirror/Examples/PickupPartyPhysics/Scripts/PickupObject.cs new file mode 100644 index 000000000..98fda3b28 --- /dev/null +++ b/Assets/Mirror/Examples/PickupPartyPhysics/Scripts/PickupObject.cs @@ -0,0 +1,12 @@ +using UnityEngine; +using Mirror; + +public class PickupObject : MonoBehaviour +{ + + public Rigidbody pickupRigidbody; + public Collider pickupCollider; + public NetworkTransformUnreliable networkTransform; // disabling is not always supported, can have weird results + + public GameObject playerHolder; // set per object if its currently picked up +} diff --git a/Assets/Mirror/Examples/PickupPartyPhysics/Scripts/PickupObject.cs.meta b/Assets/Mirror/Examples/PickupPartyPhysics/Scripts/PickupObject.cs.meta new file mode 100644 index 000000000..3eb59ff36 --- /dev/null +++ b/Assets/Mirror/Examples/PickupPartyPhysics/Scripts/PickupObject.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d95a3d991242d4718977902608114040 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Mirror/Examples/PickupPartyPhysics/Scripts/PlayerArmSlot.cs b/Assets/Mirror/Examples/PickupPartyPhysics/Scripts/PlayerArmSlot.cs index 066a0aabf..e5a77d6f0 100644 --- a/Assets/Mirror/Examples/PickupPartyPhysics/Scripts/PlayerArmSlot.cs +++ b/Assets/Mirror/Examples/PickupPartyPhysics/Scripts/PlayerArmSlot.cs @@ -1,35 +1,125 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using Mirror; -public class PlayerArmSlot : MonoBehaviour +public class PlayerArmSlot : NetworkBehaviour { public PlayerPickupParty playerPickupParty; - public Collider triggerCollider; + public Collider armTrigger; + //public Rigidbody pickedUpRigidbody; + public PickupObject pickupObject; + //public Transform collidedGameObject; - public Transform collidedGameObject; + public override void OnStartLocalPlayer() + { + // disable trigger by default, and enable if client + // this is to lighten collision and calculations on dedicated server and non owners + armTrigger.enabled = true; + } void OnTriggerEnter(Collider other) { //print("OnTriggerEnter: " + other.gameObject.name); + if (pickedUpNetworkObject != null) return; - // should be a tag, but we're not using tags in examples incase they do not copy across during import - if (other.gameObject.name.Contains("PickupObject")) + + + // should be a tag, but we're not using tags in examples incase they do not copy across during import + pickupObject = other.GetComponent(); + if(pickupObject != null) + //if ( other.gameObject.name.Contains("PickupObject")) { playerPickupParty.canPickup = true; - collidedGameObject = other.transform; + //collidedGameObject = other.transform; } } void OnTriggerExit(Collider other) { + if (pickedUpNetworkObject == null) return; //print("OnTriggerExit: " + other.gameObject.name); // should be a tag, but we're not using tags in examples incase they do not copy across during import - if (other.gameObject.name.Contains("PickupObject")) + pickupObject = other.GetComponent(); + if (pickupObject != null) + // if (other.gameObject.name.Contains("PickupObject")) { playerPickupParty.canPickup = false; - collidedGameObject = null; + pickupObject = null; + } + } + + [SyncVar(hook = nameof(OnPickupChangedHook))] + public NetworkIdentity pickedUpNetworkObject; + + void OnPickupChangedHook(NetworkIdentity _old, NetworkIdentity _new) + { + if (pickedUpNetworkObject) + { + //Debug.Log("OnPickupChangedHook: " + pickedUpNetworkObject); + PickupResult(); + } + else + { + DropResult(); + } + + + } + + private void Update() + { + if(pickedUpNetworkObject) + { + pickedUpNetworkObject.transform.position = this.transform.position; + } + } + + public void PickupResult() + { + // we cache rigidbody on pickup, not on trigger detection, so GetComponent will be called less frequently + pickupObject = pickedUpNetworkObject.GetComponent(); + pickupObject.playerHolder = this.transform.root.gameObject; + pickupObject.pickupRigidbody.useGravity = false; + pickupObject.pickupRigidbody.constraints = RigidbodyConstraints.FreezeRotation; + //pickedUpNetworkObject.GetComponent().enabled = false; + pickupObject.networkTransform.enabled = false; + armTrigger.enabled = false; + } + + public void DropResult() + { + pickupObject.pickupRigidbody.useGravity = true; + pickupObject.pickupRigidbody.constraints = RigidbodyConstraints.None; + //pickedUpNetworkObject.GetComponent().enabled = true; + armTrigger.enabled = true; + pickedUpNetworkObject = null; + pickupObject.networkTransform.enabled = true; + pickupObject.playerHolder = null; + } + + [Command] + public void CmdPickup(NetworkIdentity networkIdentity) + { + PickupObject pickupObject = networkIdentity.GetComponent(); + if (pickupObject.playerHolder == null) + { + pickedUpNetworkObject = networkIdentity; + if (isServerOnly) + { + PickupResult(); + } + } + } + + [Command] + public void CmdDrop() + { + pickedUpNetworkObject = null; + if (isServerOnly) + { + DropResult(); } } } diff --git a/Assets/Mirror/Examples/PickupPartyPhysics/Scripts/PlayerPickupParty.cs b/Assets/Mirror/Examples/PickupPartyPhysics/Scripts/PlayerPickupParty.cs index 947ecba43..1accc7a2f 100644 --- a/Assets/Mirror/Examples/PickupPartyPhysics/Scripts/PlayerPickupParty.cs +++ b/Assets/Mirror/Examples/PickupPartyPhysics/Scripts/PlayerPickupParty.cs @@ -14,8 +14,6 @@ public class PlayerPickupParty : NetworkBehaviour private float verticalSpeed = 0f; public float armRotationSpeed = 25f; public bool canPickup = false; - public Transform[] pickedUpObjects; // store pickups like an inventory - public Rigidbody[] pickedUpRigidbodies; // cache pickups to avoid re-referencing and get components public Transform[] armPivots; // acts like inventory slots public PlayerArmSlot[] playerArmSlots; // acts like inventory slots public bool freezeRotationRB = true; // if false, picked up objects rotate with collision @@ -23,6 +21,7 @@ public class PlayerPickupParty : NetworkBehaviour public CharacterController characterController; private Camera mainCamera; private int slotActive = 0; // 0 right arm, 1 left arm + private NetworkIdentity pickedUpNetworkIdentity; #if !UNITY_SERVER @@ -37,6 +36,12 @@ public override void OnStartLocalPlayer() [ClientCallback] void Update() { + //foreach (PlayerArmSlot obj in playerArmSlots) + //{ + // obj.pickedUpNetworkObject.position = + //} + //playerArmSlots[slotActive].pickedUpNetworkObject + if (!Application.isFocused) return; if (isOwned == false) { return; } @@ -143,31 +148,14 @@ void RotateArmsToMouse() [ClientCallback] void Pickup() { - if (canPickup && pickedUpObjects[slotActive] == null) + if (canPickup && playerArmSlots[slotActive].pickedUpNetworkObject == null) { - pickedUpObjects[slotActive] = playerArmSlots[slotActive].collidedGameObject; - pickedUpRigidbodies[slotActive] = pickedUpObjects[slotActive].GetComponent(); - pickedUpObjects[slotActive].SetParent(armPivots[slotActive]); - //pickedUpObjectRigidbody.isKinematic = true; - pickedUpRigidbodies[slotActive].useGravity = false; - if (freezeRotationRB) - { - pickedUpRigidbodies[slotActive].constraints = RigidbodyConstraints.FreezeRotation; - } - playerArmSlots[slotActive].triggerCollider.enabled = false; + playerArmSlots[slotActive].CmdPickup(playerArmSlots[slotActive].pickupObject.GetComponent()); canPickup = false; } - else if (pickedUpObjects[slotActive] != null) + else if (playerArmSlots[slotActive].pickedUpNetworkObject != null) { - pickedUpObjects[slotActive].SetParent(null); - //pickedUpObjectRigidbody.isKinematic = false; - pickedUpRigidbodies[slotActive].useGravity = true; - if (freezeRotationRB) - { - pickedUpRigidbodies[slotActive].constraints = RigidbodyConstraints.None; - } - playerArmSlots[slotActive].triggerCollider.enabled = true; - pickedUpObjects[slotActive] = null; + playerArmSlots[slotActive].CmdDrop(); } } #endif