/// <summary> /// Attach a given grabbable to the hand, storing the offset to the hand so it can be kept while holding. /// </summary> /// <param name="closestGrabbable">The object to be grabbed.</param> /// <param name="closestGrabbableCollider">The collider of the grabbable, not used.</param> protected virtual void Grab(Grabbable closestGrabbable, Collider closestGrabbableCollider) { GrabbedObject = closestGrabbable; GrabbedObject.GrabBegin(this, closestGrabbableCollider); OnGrabStarted?.Invoke(GrabbedObject?.gameObject); _grabbedObjectOffset = new Pose(); _grabbedObjectOffset.position = Quaternion.Inverse(transform.rotation) * (GrabbedObject.transform.position - transform.position); _grabbedObjectOffset.rotation = Quaternion.Inverse(transform.rotation) * GrabbedObject.transform.rotation; }
/// <summary> /// Attach a given grabbable to the hand, storing the offset to the hand so it can be kept while holding. /// </summary> /// <param name="closestGrabbable">The object to be grabbed.</param> protected virtual void Grab(Grabbable closestGrabbable) { _timeSinceLastGrab = Time.timeSinceLevelLoad; GrabbedObject = closestGrabbable; GrabbedObject?.GrabBegin(this); OnGrabStarted?.Invoke(GrabbedObject?.gameObject); Transform grabedTransform = closestGrabbable.transform; _grabbedObjectOffset = new Pose(); _grabbedObjectOffset.position = Quaternion.Inverse(this.transform.rotation) * (grabedTransform.position - this.transform.position); _grabbedObjectOffset.rotation = Quaternion.Inverse(this.transform.rotation) * grabedTransform.rotation; }