Skip to content

Commit 6ec1dc6

Browse files
mriisedooly123
andauthored
Pickup polishing (4) And Fly Camera (#259)
* Pickups and Fly Camera (this should've been multiple commits) Pickups: - better (mostly untested) handling of network pickups and stealing - max desktop zoop distance - proper velocity on drop - use direct transforms setting when Rigidbody reference is null - dont hover/interact if UI raycast had a UI target - when non-kinematic pickup disable gravity while held - only trigger OnInfluenceEnable/Disable if the value changed state InputModule: - movement, crouch, jump pause requests (temporary implementation) Camera: - fly movement - inherit from pickup to avoid repetetive code - camera pinning (handheld, playspace, world) - force camera preview to stay in front of face on desktop - lots of camera settings for cinematic style movement BasisParentConstraint: - blend quaternions better (little testing of this change done) - index gaurds * dont clear influencing on default remote start * start logic in wrong place after merge, dont set rigid properties if undefined * added Immobilize, DIsplayName, IsOwnerCached * added UseJiggles this allows you to turn of directly the jiggles system * Fix Merge conflicts + tweaks - rename interactDisabled to InteractableEnabled - use OnPickupDown for taking camera photos - set default interact raycast distance to 5.0 - Use new locking contexts for camera flying - Scale Camera UI based on player height (base camera object scale is 0.0003 which should be fixed at some point) * cleanup logs/using --------- Co-authored-by: dooly <[email protected]>
1 parent d6dc704 commit 6ec1dc6

File tree

16 files changed

+1151
-481
lines changed

16 files changed

+1151
-481
lines changed

Basis/Packages/com.basis.framework/Avatar/BasisAvatarPedestal.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public async void LocalAvatarLoad()
111111
}
112112
public override bool CanHover(BasisInput input)
113113
{
114-
return !pickupable &&
114+
return InteractableEnabled &&
115115
!IsPuppeted &&
116116
Inputs.IsInputAdded(input) &&
117117
input.TryGetRole(out BasisBoneTrackedRole role) &&
@@ -121,7 +121,7 @@ public override bool CanHover(BasisInput input)
121121
}
122122
public override bool CanInteract(BasisInput input)
123123
{
124-
return !pickupable &&
124+
return InteractableEnabled &&
125125
!IsPuppeted &&
126126
Inputs.IsInputAdded(input) &&
127127
input.TryGetRole(out BasisBoneTrackedRole role) &&

Basis/Packages/com.basis.framework/Basis Interactions/BasisParentConstraint.cs

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,45 +48,52 @@ public bool Evaluate(out Vector3 pos, out Quaternion rot)
4848

4949
float totalWeight = 0f;
5050
Vector3 weightedPos = Vector3.zero;
51-
Quaternion weightedRot = Quaternion.identity;
52-
53-
for (int Index = 0; Index < sources.Length; Index++)
51+
Vector4 weightedQuat = Vector4.zero;
52+
53+
for (int index = 0; index < sources.Length; index++)
5454
{
55-
ref SourceData source = ref sources[Index];
55+
ref SourceData source = ref sources[index];
5656
if (source.weight <= 0f) continue;
57-
58-
// pos offset is in local space to the sorce
57+
5958
Vector3 worldOffset = source.rotation * source.positionOffset;
6059
weightedPos += (source.position + worldOffset) * source.weight;
61-
60+
61+
// Rotation - accumulate as 4D vectors
6262
Quaternion worldRotation = source.rotation * source.rotationOffset;
63-
if (totalWeight == 0f)
64-
{
65-
weightedRot = worldRotation;
66-
}
67-
else
63+
64+
// Ensure quaternions are in same hemisphere (handle q and -q representing same rotation)
65+
if (totalWeight > 0f && Vector4.Dot(weightedQuat.normalized, new Vector4(worldRotation.x, worldRotation.y, worldRotation.z, worldRotation.w)) < 0f)
6866
{
69-
weightedRot = Quaternion.Slerp(weightedRot, worldRotation, source.weight / (totalWeight + source.weight));
67+
worldRotation = new Quaternion(-worldRotation.x, -worldRotation.y, -worldRotation.z, -worldRotation.w);
7068
}
71-
69+
70+
weightedQuat += new Vector4(worldRotation.x, worldRotation.y, worldRotation.z, worldRotation.w) * source.weight;
7271
totalWeight += source.weight;
7372
}
74-
75-
// apply weighted average
73+
74+
// Normalize results
7675
if (totalWeight > 0f)
7776
{
7877
weightedPos /= totalWeight;
78+
weightedQuat /= totalWeight;
79+
80+
// Convert back to quaternion and normalize
81+
Quaternion blendedRot = new Quaternion(weightedQuat.x, weightedQuat.y, weightedQuat.z, weightedQuat.w).normalized;
82+
83+
// Apply global weight
84+
pos = Vector3.Lerp(_restPosition, weightedPos, GlobalWeight);
85+
rot = Quaternion.Slerp(_restRotation, blendedRot, GlobalWeight);
86+
return true;
7987
}
80-
81-
// global weight interpolates original with the calculated transform
82-
pos = Vector3.Lerp(_restPosition, weightedPos, GlobalWeight);
83-
rot = Quaternion.Slerp(_restRotation, weightedRot, GlobalWeight);
84-
85-
return true;
88+
89+
pos = _restPosition;
90+
rot = _restRotation;
91+
return false;
8692
}
8793

8894
public void UpdateSourcePositionAndRotation(int Index, Vector3 position, Quaternion rotation)
8995
{
96+
if (Index < 0 || Index >= sources.Length) return;
9097
var source = sources[Index];
9198
source.position = position;
9299
source.rotation = rotation;
@@ -95,6 +102,7 @@ public void UpdateSourcePositionAndRotation(int Index, Vector3 position, Quatern
95102

96103
public void SetOffsetPositionAndRotation(int Index, Vector3 positionOffset, Quaternion rotationOffset)
97104
{
105+
if (Index < 0 || Index >= sources.Length) return;
98106
var source = sources[Index];
99107
source.positionOffset = positionOffset;
100108
source.rotationOffset = rotationOffset;

Basis/Packages/com.basis.framework/Basis Interactions/InteractableObject.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,37 +12,39 @@ public abstract class InteractableObject : MonoBehaviour
1212
[Header("Interactable Settings")]
1313

1414
[SerializeField]
15-
private bool disableInfluence = false;
15+
private bool interactableEnabled = true;
1616
// NOTE: unity editor will not use the set function so setting disabling Interact in play will not cleanup inputs
17-
public bool pickupable
17+
public bool InteractableEnabled
1818
{
19-
get => disableInfluence;
19+
get => interactableEnabled;
2020
set
2121
{
2222
// remove hover and interacting on disable
23-
if (value)
23+
if (!value)
2424
{
2525
ClearAllInfluencing();
26-
OnInfluenceDisable?.Invoke();
26+
if (interactableEnabled)
27+
OnInfluenceDisable?.Invoke();
2728
}
2829
else
2930
{
30-
OnInfluenceEnable?.Invoke();
31+
if (!interactableEnabled)
32+
OnInfluenceEnable?.Invoke();
3133
}
32-
disableInfluence = value;
34+
interactableEnabled = value;
3335
}
3436
}
37+
3538
[Space(10)]
3639
public bool Equippable = false;
3740

3841
[NonSerialized]
39-
public bool RequiresUpdateLoop = false;
42+
internal bool RequiresUpdateLoop = false;
43+
4044
/// <summary>
41-
/// 1. to block interaction when puppeted.
42-
/// 2. (example) iskinematic set
43-
/// depending on puppeted state.
45+
/// Whether this object is controlled elsewhere.
46+
/// This is used to block interaction, set iskinematic, ect.
4447
/// </summary>
45-
// [HideInInspector]
4648
public bool IsPuppeted = false;
4749
// Delegates for interaction events
4850
public Action<BasisInput> OnInteractStartEvent;
@@ -174,6 +176,9 @@ public virtual void OnHoverEnd(BasisInput input, bool willInteract)
174176
OnHoverEndEvent?.Invoke(input, willInteract);
175177
}
176178

179+
/// <summary>
180+
/// Interactable event loop, called every frame on AfterFinalMove when an input has it as a target and RequiresUpdateLoop is true.
181+
/// </summary>
177182
public abstract void InputUpdate();
178183

179184
/// <summary>
@@ -207,7 +212,7 @@ public virtual void ClearAllInfluencing()
207212
/// <returns></returns>
208213
public virtual bool IsInfluencable(BasisInput input)
209214
{
210-
return !pickupable && (CanHover(input) || CanInteract(input));
215+
return InteractableEnabled && (CanHover(input) || CanInteract(input));
211216
}
212217

213218
public virtual void StartRemoteControl()

0 commit comments

Comments
 (0)