public void DetachIfAttached() { if (hand) { hand.DetachIfAny(); } }
private void OnDisable() { hand?.DetachIfAny(); hand2?.DetachIfAny(); updateEvents.onDrop.Invoke(); if (outline) { outline.enabled = false; } }
private void FixedUpdate() { if (mode == Mode.OneHandRotation) { DealOneHandRotation(); } updateCallbacks.updatePitch.Invoke(input_pitchyawroll.x); updateCallbacks.updateYaw.Invoke(input_pitchyawroll.y); updateCallbacks.updateRoll.Invoke(input_pitchyawroll.z); updateCallbacks.updateX.Invoke(input_xyz.x); updateCallbacks.updateY.Invoke(input_xyz.y); updateCallbacks.updateZ.Invoke(input_xyz.z); updateCallbacks.updateTrigger.Invoke(input_trigger); if (hand && hand.input_grip < .5f) { hand.DetachIfAny(); } if (hand2 && hand2.input_grip < .5f) { hand2.DetachIfAny(); } }
public void TransforAttached(XRHand other) { if (attached) { other.DetachIfAny(); other.attached = attached; foreach (var c in attached.GetComponentsInChildren <Collider>()) { other.IgnoreCollider(c); } attached = null; SendHapticImpulse(hapticSettings.detachStrength, hapticSettings.detachDuration); other.SendHapticImpulse(other.hapticSettings.attachStrength, other.hapticSettings.attachDuration); } }
private void FixedUpdate() { float totalRotation = 0, totalWeight = 0; if (attachedLeftHand) { Vector3 p1 = pivot.InverseTransformPoint(attachedLeftHand.position); Vector3 p2 = leftRef; p1.z = 0; p2.z = 0; if (p1.sqrMagnitude > 0 && p2.sqrMagnitude > 0) { totalRotation += Vector3.SignedAngle(p2, p1, Vector3.forward); totalWeight += 1; } leftRef = p1; } if (attachedRightHand) { Vector3 p1 = pivot.InverseTransformPoint(attachedRightHand.position); Vector3 p2 = rightRef; p1.z = 0; p2.z = 0; if (p1.sqrMagnitude > 0 && p2.sqrMagnitude > 0) { totalRotation += Vector3.SignedAngle(p2, p1, Vector3.forward); totalWeight += 1; } rightRef = p1; } float rotation = totalWeight > 0?totalRotation / totalWeight:0; currentRotation = Mathf.Clamp(currentRotation + rotation, -maxRotation, maxRotation); steeringWheel.localRotation = Quaternion.Euler(0, 0, currentRotation); float throttle = 0, brake = 0; if (attachedRightHand) { throttle = attachedRightHand.input_trigger; } if (attachedLeftHand) { brake = attachedLeftHand.input_trigger; } if (brake > .1f) { throttle = -brake; } float steering = Mathf.Clamp(currentRotation / maxRotation, -1, 1); updateInputs.updateSteering.Invoke(steering); updateInputs.updateThrottle.Invoke(throttle); if (attachedLeftHand && attachedLeftHand.input_grip < .5f) { attachedLeftHand.DetachIfAny(); } if (attachedRightHand && attachedRightHand.input_grip < .5f) { attachedRightHand.DetachIfAny(); } }