void Start() { playerRigidBody = GetComponent <Rigidbody>(); if (playerRigidBody) { playerRigidBody.freezeRotation = true; } originalRotation = transform.localRotation; //playerRigidBody.position = Vector3.zero; HandScript = Hand.GetComponent <HandGrab>(); }
protected virtual void ComputeBestSnapAddress(ref SnapAddress snapAddress) { IEnumerable<HandGrabInteractable> interactables = HandGrabInteractable.Registry.List(this); float bestFingerScore = -1f; float bestPoseScore = -1f; foreach (HandGrabInteractable interactable in interactables) { float fingerScore = 1.0f; if (!HandGrab.ComputeShouldSelect(this, interactable, out GrabTypeFlags selectingGrabTypes)) { fingerScore = HandGrab.ComputeHandGrabScore(this, interactable, out selectingGrabTypes); } if (fingerScore < bestFingerScore) { continue; } bool usePinchPoint = CanSnapToPinchPoint(interactable, selectingGrabTypes); Pose grabPoint = usePinchPoint ? _trackedPinchPose : _trackedGripPose; bool poseFound = interactable.CalculateBestPose(grabPoint, Hand.Scale, Hand.Handedness, ref _cachedBestHandPose, ref _cachedBestSnapPoint, out bool usesHandPose, out float poseScore); if (!poseFound) { continue; } if (fingerScore > bestFingerScore || poseScore > bestPoseScore) { bestFingerScore = fingerScore; bestPoseScore = poseScore; HandPose handPose = usesHandPose ? _cachedBestHandPose : null; snapAddress.Set(interactable, handPose, _cachedBestSnapPoint, usePinchPoint); } } if (bestFingerScore < 0) { snapAddress.Clear(); } }
/// <summary> /// Each call while the hand is selecting/grabbing an interactable, it moves the item to the /// new position while also attracting it towards the hand if the snapping mode requires it. /// /// In some cases the parameter can be null, for example if the selection was interrupted /// by another hand grabbing the object. In those cases it will come out of the release /// state once the grabbing gesture properly finishes. /// </summary> /// <param name="interactable">The selected item</param> protected override void DoSelectUpdate() { HandGrabInteractable interactable = _selectedInteractable; if (interactable == null) { _currentSnap.Clear(); ShouldUnselect = true; return; } Pose grabbingPoint = PoseUtils.Multiply(_trackedGripPose, _snapOffset); _movement.UpdateTarget(grabbingPoint); _movement.Tick(); HandGrab.StoreGrabData(this, interactable, ref _lastInteractableData); ShouldUnselect = HandGrab.ComputeShouldUnselect(this, interactable); }
/// <summary> /// Each call while the interactor is hovering, it checks whether there is an interaction /// being hovered and sets the target snapping address to it. In the HandToObject snapping /// behaviors this is relevant as the hand can approach the object progressively even before /// a true grab starts. /// </summary> protected override void DoHoverUpdate() { base.DoHoverUpdate(); if (_currentSnap.IsValidAddress) { SnapStrength = HandGrab.ComputeHandGrabScore(this, Interactable, out GrabTypeFlags hoverGrabTypes); SnapData = _currentSnap; } else { SnapStrength = 0f; SnapData = null; } if (Interactable != null) { ShouldSelect = HandGrab.ComputeShouldSelect(this, Interactable, out GrabTypeFlags selectingGrabTypes); } }
void Start() { handGrab = GetComponent <HandGrab>(); }
public HandFingerFlags SnappingFingers() { return HandGrab.GrabbingFingers(this, SelectedInteractable); }