Skip to content

Commit e751a06

Browse files
committed
1.5.0
- Reworked grab system - Cannot steal crates anymore - Fixed a few grab/authority bugs
1 parent a9ed137 commit e751a06

16 files changed

Lines changed: 453 additions & 163 deletions

Assets/Prefabs/Characters/Player.prefab

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6014,14 +6014,14 @@ MonoBehaviour:
60146014
archetypeData:
60156015
type: 4
60166016
minRange: 0
6017-
maxRange: 5
6017+
maxRange: 10
60186018
sampleRate: 20
60196019
floatCompression: 2
60206020
fields:
60216021
- type: 4
6022-
bits: 13
6022+
bits: 14
60236023
minRange: 0
6024-
maxRange: 5
6024+
maxRange: 10
60256025
precision: 0.001
60266026
floatCompression: 2
60276027
sharedBinding: {fileID: 0}

Assets/Prefabs/Gameplay/Crate.prefab

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ MonoBehaviour:
137137
bakedScriptType: Coherence.Generated.CoherenceSyncCrate_id1, Assembly-CSharp
138138
approveAuthorityTransferRequests: 1
139139
simulationType: 0
140-
authorityTransferType: 2
140+
authorityTransferType: 1
141141
orphanedBehavior: 1
142142
lifetimeType: 1
143143
uniquenessType: 1
@@ -151,6 +151,7 @@ MonoBehaviour:
151151
- rid: 2368829912872124485
152152
- rid: 2919437089004584960
153153
- rid: 2919437089004584961
154+
- rid: 134368298502455379
154155
onNetworkedInstantiation:
155156
m_PersistentCalls:
156157
m_Calls: []
@@ -171,6 +172,53 @@ MonoBehaviour:
171172
RefIds:
172173
- rid: -2
173174
type: {class: , ns: , asm: }
175+
- rid: 134368298502455379
176+
type: {class: BoolBinding, ns: Coherence.Toolkit.Bindings.ValueBindings, asm: Coherence.Toolkit}
177+
data:
178+
descriptor:
179+
rid: 134368298502455380
180+
routing: 0
181+
isPredicted: 0
182+
defaultInterpolationPath:
183+
guid: 7adfb1f9-df9d-4d92-8091-2a9e293b28d5
184+
archetypeData:
185+
type: 3
186+
minRange: 0
187+
maxRange: 0
188+
sampleRate: 20
189+
floatCompression: 0
190+
fields:
191+
- type: 3
192+
bits: 1
193+
minRange: 0
194+
maxRange: 0
195+
precision: 0
196+
floatCompression: 0
197+
sharedBinding: {fileID: 0}
198+
unityComponent: {fileID: 6525610836190113121}
199+
coherenceSync: {fileID: 0}
200+
interpolationSettings: {fileID: 11400000, guid: ae4419d1d9a8643709bf5f6b90c584a5,
201+
type: 2}
202+
- rid: 134368298502455380
203+
type: {class: Descriptor, ns: Coherence.Toolkit.Bindings, asm: Coherence.Toolkit}
204+
data:
205+
name: isBeingCarried
206+
monoAssemblyType: System.Boolean, mscorlib
207+
required: 1
208+
enforcesLODingWhenFieldsOverriden: 1
209+
valueSyncCallbackName:
210+
memberType: 4
211+
parameterAssemblyTypes: []
212+
ownerType:
213+
assemblyQualifiedName: Grabbable, Assembly-CSharp, Version=0.0.0.0, Culture=neutral,
214+
PublicKeyToken=null
215+
CustomData:
216+
rid: -2
217+
bindingType:
218+
assemblyQualifiedName: Coherence.Toolkit.Bindings.ValueBindings.BoolBinding,
219+
Coherence.Toolkit, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
220+
oldName:
221+
oldParameterAssemblyTypes: []
174222
- rid: 2368829912872124484
175223
type: {class: PositionBinding, ns: Coherence.Toolkit.Bindings.TransformBindings,
176224
asm: Coherence.Toolkit}
@@ -415,6 +463,7 @@ MonoBehaviour:
415463
m_Script: {fileID: 11500000, guid: 24ccdb6d7545417896337d114fcb54ae, type: 3}
416464
m_Name:
417465
m_EditorClassIdentifier:
466+
isBeingCarried: 0
418467
--- !u!114 &4939570989761225410
419468
MonoBehaviour:
420469
m_ObjectHideFlags: 0

Assets/Scenes/5_ComplexHierarchies.unity

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24941,6 +24941,11 @@ PrefabInstance:
2494124941
m_Modification:
2494224942
m_TransformParent: {fileID: 0}
2494324943
m_Modifications:
24944+
- target: {fileID: 294465140271106047, guid: 27f1ac5097d4ee4409fbb87ad14f76c2,
24945+
type: 3}
24946+
propertyPath: coherenceUUID
24947+
value: 63fdad87-e751-4401-9e5d-1dbb9e93a50a
24948+
objectReference: {fileID: 0}
2494424949
- target: {fileID: 1522740331349769034, guid: 27f1ac5097d4ee4409fbb87ad14f76c2,
2494524950
type: 3}
2494624951
propertyPath: m_RootOrder
@@ -25006,7 +25011,13 @@ PrefabInstance:
2500625011
propertyPath: m_Materials.Array.data[0]
2500725012
value:
2500825013
objectReference: {fileID: 2100000, guid: b0106947e8e6caa488768d27ed8ac352, type: 2}
25009-
m_RemovedComponents: []
25014+
- target: {fileID: 6525610836190113121, guid: 27f1ac5097d4ee4409fbb87ad14f76c2,
25015+
type: 3}
25016+
propertyPath: m_Enabled
25017+
value: 1
25018+
objectReference: {fileID: 0}
25019+
m_RemovedComponents:
25020+
- {fileID: 6525610836190113121, guid: 27f1ac5097d4ee4409fbb87ad14f76c2, type: 3}
2501025021
m_SourcePrefab: {fileID: 100100000, guid: 27f1ac5097d4ee4409fbb87ad14f76c2, type: 3}
2501125022
--- !u!114 &1327512620 stripped
2501225023
MonoBehaviour:

Assets/Scripts/Player/Grab.cs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System;
2-
using Coherence.Toolkit;
31
using UnityEngine;
42

53
public class Grab : MonoBehaviour
@@ -12,20 +10,17 @@ public class Grab : MonoBehaviour
1210
private Grabbable _grabbedObject;
1311
private Rigidbody _grabbedObjectRB;
1412
private Collider _grabbedObjectCollider;
15-
private CoherenceSync _grabbedObjectSync;
1613

1714
public void PickUp(Grabbable target)
1815
{
1916
animator.SetBool("CarryingBig", true);
20-
_grabbedObjectRB = target.gameObject.GetComponent<Rigidbody>();
17+
_grabbedObject = target;
18+
_grabbedObjectRB = _grabbedObject.GetComponent<Rigidbody>();
19+
_grabbedObjectCollider = _grabbedObject.GetComponent<Collider>();
2120
_grabbedObjectRB.isKinematic = true;
22-
_grabbedObjectCollider = target.GetComponent<Collider>();
2321
_grabbedObjectCollider.enabled = false;
24-
_grabbedObject = target;
2522
_grabbedObject.transform.SetParent(holdSocket, false);
2623
_grabbedObject.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);
27-
_grabbedObjectSync = _grabbedObject.GetComponent<CoherenceSync>();
28-
_grabbedObjectSync.OnStateRemote.AddListener(OnGrabbableTaken);
2924
IsCarryingSomething = true;
3025
}
3126

@@ -35,12 +30,12 @@ public void PickUp(Grabbable target)
3530
/// </summary>
3631
public void Drop(float throwStrength = 0f)
3732
{
38-
_grabbedObjectCollider.enabled = true;
3933
_grabbedObject.transform.SetParent(null, true);
4034
_grabbedObjectRB.isKinematic = false;
4135
_grabbedObjectRB.AddForce(throwStrength * transform.forward, ForceMode.VelocityChange );
4236
_grabbedObjectRB.AddTorque( -transform.right * throwStrength * 1f, ForceMode.VelocityChange );
43-
37+
_grabbedObject.Release();
38+
4439
LetGo();
4540
}
4641

@@ -52,23 +47,14 @@ public void Drop(float throwStrength = 0f)
5247
private void LetGo()
5348
{
5449
animator.SetBool("CarryingBig", false);
55-
_grabbedObjectSync.OnStateRemote.RemoveListener(OnGrabbableTaken);
50+
_grabbedObjectCollider.enabled = true;
5651

5752
_grabbedObjectRB = null;
5853
_grabbedObjectCollider = null;
5954
_grabbedObject = null;
6055
IsCarryingSomething = false;
6156
}
6257

63-
/// <summary>
64-
/// Happens when another player steals the object from the holder's hands,
65-
/// or if the object gets burnt.
66-
/// </summary>
67-
private void OnGrabbableTaken()
68-
{
69-
LetGo();
70-
}
71-
7258
private void OnDisable()
7359
{
7460
// Since the player gets destroyed when exiting Play mode,

Assets/Scripts/Player/GrabInput.cs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
using UnityEngine;
22
using UnityEngine.InputSystem;
3-
using UnityEngine.Serialization;
43

54
public class GrabInput : MonoBehaviour
65
{
76
public InputActionReference grabAction;
87
public Move moveScript;
98

109
private Grab _grabScript;
11-
private Grabbable _grabbableTarget;
10+
private Grabbable _potentialTarget;
11+
private Grabbable _grabbable;
1212
private bool _canToss;
1313

1414
private void Awake()
@@ -34,16 +34,16 @@ private void OnTriggerEnter(Collider other)
3434

3535
// Found a grabbable object
3636
if (other.CompareTag("Grabbable"))
37-
_grabbableTarget = other.gameObject.GetComponent<Grabbable>();
37+
_potentialTarget = other.gameObject.GetComponent<Grabbable>();
3838
}
3939

4040
private void OnTriggerExit(Collider other)
4141
{
4242
if (_grabScript.IsCarryingSomething)
4343
return;
4444

45-
if (other.gameObject.GetComponent<Grabbable>() == _grabbableTarget)
46-
_grabbableTarget = null;
45+
if (other.gameObject.GetComponent<Grabbable>() == _potentialTarget)
46+
_potentialTarget = null;
4747
}
4848

4949
/// <summary>
@@ -53,44 +53,52 @@ private void OnGrabActionPerformed(InputAction.CallbackContext obj)
5353
{
5454
if (!_grabScript.IsCarryingSomething)
5555
{
56-
if (_grabbableTarget == null)
57-
return;
56+
// Pick up
57+
if (_potentialTarget != null
58+
&& !_potentialTarget.isBeingCarried)
59+
{
60+
_canToss = false;
5861

59-
_canToss = false;
60-
61-
// Attempt to pick up Grabbable
62-
_grabbableTarget.PickupValidated += OnPickUpValidated;
63-
_grabbableTarget.RequestPickup(); // This will fire an authority request if entity is remote
62+
// Pick up Grabbable
63+
_grabbable = _potentialTarget;
64+
_grabbable.PickupValidated += OnPickUpValidated;
65+
_grabbable.RequestPickup(); // This will fire an authority request if the entity is remote
66+
}
6467
}
6568
else if(_canToss)
6669
{
6770
// Release or throw
6871
float speed = moveScript.ThrowSpeed();
6972
_grabScript.Drop(speed);
7073
moveScript.ApplyThrowPushback(speed);
74+
_grabbable = null;
7175
}
7276
}
7377

7478
/// <summary>
7579
/// Received a response from the grabbable we're trying to pick up.
76-
/// Since the object could be remote, this includes a request of authority,
77-
/// which might lead it to fail if the object is set to not concede authority.
80+
/// Since the object could be remote, this includes a request of authority.
7881
/// </summary>
7982
/// <param name="success">Whether the pickup was authorized or not.</param>
8083
private void OnPickUpValidated(bool success)
8184
{
82-
_grabbableTarget.PickupValidated -= OnPickUpValidated;
85+
_grabbable.PickupValidated -= OnPickUpValidated;
8386
_canToss = true;
8487

8588
if (success)
8689
{
87-
PickUp();
90+
// The object was just laying around
91+
_grabScript.PickUp(_grabbable);
92+
_potentialTarget = null;
93+
}
94+
else
95+
{
96+
// Pickup can fail when a grabbable that was free up to a moment ago JUST
97+
// got picked up by another player on the network.
98+
// Locally this client is not aware yet because the Grabbable.isBeingCarried property
99+
// hasn't synced yet, but when requesting authority for the pickup - they get rejected
100+
// in the Grabbable.OnAuthorityRequested callback.
101+
_grabbable = null;
88102
}
89-
}
90-
91-
private void PickUp()
92-
{
93-
_grabScript.PickUp(_grabbableTarget);
94-
_grabbableTarget = null;
95103
}
96104
}

0 commit comments

Comments
 (0)