Skip to content

Commit

Permalink
Revert "fix a bit picking up weird glitches"
Browse files Browse the repository at this point in the history
This reverts commit 035dafa.
  • Loading branch information
stilnat committed Feb 4, 2025
1 parent 035dafa commit c7c4567
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ private void ReleaseGrab()

private void SetUpGrab(bool withTwoHands)
{
_mainHand.Hold.HandTargetFollow.Follow(_grabbedObject.transform.position);
_mainHand.Hold.HandTargetFollowTransform(_grabbedObject.transform);

// Needed if this has been changed elsewhere
_mainHand.Hold.PickupIkConstraint.data.tipRotationWeight = 1f;

// Reproduce changes on secondary hand if necessary.
if (withTwoHands)
{
_secondaryHand.Hold.HandTargetFollow.Follow(_grabbedObject.transform.position);
_secondaryHand.Hold.HandTargetFollowTransform(_grabbedObject.transform);
_secondaryHand.Hold.PickupIkConstraint.data.tipRotationWeight = 1f;
}

// Set up the look at target locker on the item to pick up.
Controller.LookAtTargetLocker.Follow(_grabbedObject.transform.position);
Controller.LookAtTargetLocker.Follow(_grabbedObject.transform, true);
OrientTargetForHandRotation(_mainHand, _grabbedObject.transform.position);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void HitAnimate()
// We start by setting the pickup IK target back on the item hold
_mainHand.Hold.PickupIkConstraint.weight = 1;
Transform parent = _holdable.GetHold(true, _mainHand.HandType);
_mainHand.Hold.HandTargetFollow.Follow(parent.position);
_mainHand.Hold.HandTargetFollowTransform(parent);

// Compute the rotation of the player's root transform when looking at the hit position
Vector3 directionFromTransformToTarget = _targetHitPosition - _rootTransform.position;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private void SetupInteract()
// disable position constraint the time of the interaction
_hand.Hold.ItemPositionConstraint.weight = 0f;
_hand.Hold.PickupIkConstraint.weight = 1f;
_hand.Hold.HandTargetFollowTransform(null);
_hand.Hold.HandIkTarget.position = _hand.HandBone.position;
Controller.LookAtTargetLocker.transform.position = _targetPosition;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private void SetUpPickup(bool withTwoHands)
OrientTargetForHandRotation(_mainHand, _holdable.transform.position);

// Place hand ik target on the item, at their respective position and rotation.
_mainHand.Hold.HandTargetFollow.Follow(_holdable.GetHold(true, _mainHand.HandType).position);
_mainHand.Hold.HandTargetFollowHold(false, _holdable, false);

// Needed if this has been changed elsewhere
_mainHand.Hold.PickupIkConstraint.data.tipRotationWeight = 1f;
Expand All @@ -76,13 +76,13 @@ private void SetUpPickup(bool withTwoHands)
if (withTwoHands)
{
OrientTargetForHandRotation(_secondaryHand, _holdable.transform.position);
_secondaryHand.Hold.HandTargetFollow.Follow(_holdable.GetHold(false, _secondaryHand.HandType).position);
_secondaryHand.Hold.HandTargetFollowHold(true, _holdable);
_secondaryHand.Hold.PickupIkConstraint.data.tipRotationWeight = 1f;
_secondaryHand.Hold.HoldIkConstraint.data.targetRotationWeight = 0f;
}

// Set up the look at target locker on the item to pick up.
Controller.LookAtTargetLocker.Follow(_holdable.transform.position);
Controller.LookAtTargetLocker.Follow(_holdable.transform, true);
}

[Client]
Expand Down Expand Up @@ -113,12 +113,11 @@ private void PickupReach(bool withTwoHands)
OnStart(() => RestorePosition(Controller.PositionController)));

// At the same time start getting the right rotation for the hand
InteractionSequence.Join(DOTween.To(
() => _mainHand.Hold.HoldIkConstraint.data.targetRotationWeight,
x => _mainHand.Hold.HoldIkConstraint.data.targetRotationWeight = x,
1f,
_itemReachDuration).OnStart(() =>
InteractionSequence.Join(DOTween.To(() => _mainHand.Hold.HoldIkConstraint.data.targetRotationWeight, x => _mainHand.Hold.HoldIkConstraint.data.targetRotationWeight = x, 1f, _itemReachDuration).OnStart(() =>
{
_mainHand.Hold.HandTargetFollowHold(false, _holdable, true, _itemReachDuration);

// Controller.HoldController.BringToHand(_mainHand, _holdable, _itemReachDuration);
}));

// At the same time, remove the pickup constraint
Expand All @@ -127,25 +126,14 @@ private void PickupReach(bool withTwoHands)
// Reproduce changes on second hand if picking up with two hands
if (withTwoHands)
{
InteractionSequence.Join(DOTween.To(
() => _secondaryHand.Hold.HoldIkConstraint.weight,
x => _secondaryHand.Hold.HoldIkConstraint.weight = x,
1f,
_itemReachDuration));

InteractionSequence.Join(DOTween.To(
() => _secondaryHand.Hold.HoldIkConstraint.data.targetRotationWeight,
x => _secondaryHand.Hold.HoldIkConstraint.data.targetRotationWeight = x,
1f,
_itemReachDuration)).OnStart(() =>
InteractionSequence.Join(DOTween.To(() => _secondaryHand.Hold.HoldIkConstraint.weight, x => _secondaryHand.Hold.HoldIkConstraint.weight = x, 1f, _itemReachDuration));

InteractionSequence.Join(DOTween.To(() => _secondaryHand.Hold.HoldIkConstraint.data.targetRotationWeight, x => _secondaryHand.Hold.HoldIkConstraint.data.targetRotationWeight = x, 1f, _itemReachDuration)).OnStart(() =>
{
_secondaryHand.Hold.HandTargetFollowHold(true, _holdable, true, _itemReachDuration);
});

InteractionSequence.Join(DOTween.To(
() => _secondaryHand.Hold.PickupIkConstraint.weight,
x => _secondaryHand.Hold.PickupIkConstraint.weight = x,
0f,
_itemReachDuration));
InteractionSequence.Join(DOTween.To(() => _secondaryHand.Hold.PickupIkConstraint.weight, x => _secondaryHand.Hold.PickupIkConstraint.weight = x, 0f, _itemReachDuration));
}

InteractionSequence.OnComplete(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override void Cancel()
_mainHand.Hold.ItemPositionConstraint.weight = 1f;

// Place pickup and hold target lockers on the item, at their respective position and rotation.
_mainHand.Hold.HandTargetFollow.Follow(_placedObject.Position);
_mainHand.Hold.HandTargetFollowHold(false, _placedObject);

// Move and rotate item toward its constrained position.
_placedObject.transform.parent = _mainHand.Hold.ItemPositionTargetLocker;
Expand Down
14 changes: 14 additions & 0 deletions Assets/Scripts/SS3D/Systems/Entities/Humanoid/Hands/HandHoldIk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,20 @@ public class HandHoldIk : NetworkActor, IInteractiveTool
[field: SerializeField]
public TargetFollow HandTargetFollow { get; private set; }

public void HandTargetFollowHold(bool secondary, AbstractHoldable holdProvider, bool simulateRotation = true, float timeToReachRotation = 0f)
{
Transform parent = holdProvider.GetHold(!secondary, Hand.HandType);
HandTargetFollowTransform(parent, simulateRotation, timeToReachRotation);
}

/// <summary>
/// Put the right IK target as a child of another transform, setting its position to zero and its rotation to be the same as the parent one (or optionnally not doing it).
/// </summary>
public void HandTargetFollowTransform(Transform parent, bool simulateRotation = true, float timeToReachRotation = 0f)
{
HandTargetFollow.Follow(parent, simulateRotation, timeToReachRotation);
}

/// <summary>
/// Remove the hold ik constraint weight on an item and unparent it. (Move that to Hold controller ?)
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private void RemoveItem(Hand hand)
{
UpdatePoseWithItem(oppositeHand, oppositeHand.ItemHeld.Holdable, 0.2f);
hand.Hold.HoldIkConstraint.weight = 1f;
hand.Hold.HandTargetFollow.Follow(oppositeHand.ItemHeld.Holdable.Position);
hand.Hold.HandTargetFollowHold(true, oppositeHand.ItemHeld.Holdable);
}
}

Expand Down
26 changes: 22 additions & 4 deletions Assets/Scripts/SS3D/Utils/TransformManipulations/TargetFollow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,35 @@
/// </summary>
public class TargetFollow : MonoBehaviour
{
public Vector3 Followed { get; private set; }

public Transform Followed { get; private set; }

private bool _reproduceRotation;

private float _timeToReachRotation;

private float _timing;

public void Follow(Vector3 position)
public void Follow(Transform followed, bool reproduceRotation, float timeToReachRotation = 0)
{
Followed = position;
Followed = followed;
_reproduceRotation = reproduceRotation;
_timeToReachRotation = timeToReachRotation;
_timing = 0;
}

private void LateUpdate()
{
transform.position = Followed;
if (Followed is null)
{
return;
}

transform.position = Followed.position;

if (!_reproduceRotation) { return; }

transform.rotation = _timing >= _timeToReachRotation ? Followed.rotation : Quaternion.Slerp(transform.rotation, Followed.rotation, _timing/_timeToReachRotation);
_timing += Time.deltaTime;
}
}

0 comments on commit c7c4567

Please sign in to comment.