Transform getArrowRest() { if (bowGrabbable.GetPrimaryGrabber() != null && bowGrabbable.GetPrimaryGrabber().HandSide == ControllerHand.Right && ArrowRestLeftHanded != null) { return(ArrowRestLeftHanded); } return(ArrowRest); }
void Update() { // Something is holding the handle. Point at the Grabber if (HandleGrabbable != null && HandleGrabbable.BeingHeld) { Quaternion rot = Quaternion.LookRotation(HandleGrabbable.GetPrimaryGrabber().transform.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rot, Time.deltaTime * 10); Vector3 currentPos = transform.localEulerAngles; float constrainedY = Mathf.Clamp(currentPos.y, LocalYMin, LocalYMax); transform.localEulerAngles = new Vector3(initialRot.x, constrainedY, initialRot.z); } // Point at the LookAt Transform else { Quaternion rot = Quaternion.LookRotation(LookAt.position - transform.position); transform.rotation = Quaternion.Slerp(transform.rotation, rot, Time.deltaTime * Speed); Vector3 currentPos = transform.localEulerAngles; float constrainedY = Mathf.Clamp(currentPos.y, LocalYMin, LocalYMax); transform.localEulerAngles = new Vector3(initialRot.x, constrainedY, initialRot.z); } }
void doJoystickLook() { // Do Lever Look if (grab != null && grab.BeingHeld) { rb.velocity = Vector3.zero; rb.angularVelocity = Vector3.zero; // Store original rotation to be used with smooth look Quaternion originalRot = transform.rotation; // Use the Grabber as our look target // Convert to local position so we can remove the x axis Vector3 localTargetPosition = transform.InverseTransformPoint(grab.GetPrimaryGrabber().transform.position); // Convert back to world position Vector3 targetPosition = transform.TransformPoint(localTargetPosition); transform.LookAt(targetPosition, transform.up); if (UseSmoothLook) { Quaternion newRot = transform.rotation; transform.rotation = originalRot; transform.rotation = Quaternion.Lerp(transform.rotation, newRot, Time.fixedDeltaTime * SmoothLookSpeed); } } else if (grab != null && !grab.BeingHeld && rb.isKinematic) { transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.identity, Time.deltaTime * SmoothLookSpeed); rb.velocity = Vector3.zero; rb.angularVelocity = Vector3.zero; } }
void doLeverLook() { // Do Lever Look if (grab != null && grab.BeingHeld) { transform.LookAt(grab.GetPrimaryGrabber().transform, lookDirection); transform.localEulerAngles += LookOffset; } }
bool canGrabArrowFromKnock() { // Setting override if (!CanGrabArrowFromKnock) { return(false); } // Use opposite hand of what's holding the bow ControllerHand hand = bowGrabbable.GetControllerHand(bowGrabbable.GetPrimaryGrabber()) == ControllerHand.Left ? ControllerHand.Right : ControllerHand.Left; return(CanGrabArrow && getTriggerInput(hand) > 0.75f && !holdingArrow); }
void doLeverLook() { // Do Lever Look if (grab != null && grab.BeingHeld) { transform.LookAt(grab.GetPrimaryGrabber().transform, lookDirection); transform.localEulerAngles += LookOffset; DebugVal = transform.localEulerAngles.x; //float leverX = Mathf.Clamp(transform.localEulerAngles.x, MinDegrees, MaxDegrees); //transform.localEulerAngles = new Vector3(leverX, 0, 0); } }
void doLeverLook() { // Do Lever Look if (grab != null && grab.BeingHeld) { // Use the grabber as our look target. Transform target = grab.GetPrimaryGrabber().transform; // Store original rotation to be used with smooth look Quaternion originalRot = transform.rotation; // Convert to local position so we can remove the x axis Vector3 localTargetPosition = transform.InverseTransformPoint(target.position); // Remove local X axis as this would cause the lever to rotate incorrectly localTargetPosition.x = 0f; // Convert back to world position Vector3 targetPosition = transform.TransformPoint(localTargetPosition); transform.LookAt(targetPosition, transform.up); // Get the initial hand offset so our Lever doesn't jump to the grabber when we first grab it if (initialOffset == Quaternion.identity) { initialOffset = originalRot * Quaternion.Inverse(transform.rotation); } if (!SnapToGrabber) { transform.rotation = transform.rotation * initialOffset; } if (UseSmoothLook) { Quaternion newRot = transform.rotation; transform.rotation = originalRot; transform.rotation = Quaternion.Lerp(transform.rotation, newRot, Time.deltaTime * SmoothLookSpeed); } } else if (grab != null && !grab.BeingHeld) { if (ReturnToCenter && AllowPhysicsForces == false) { transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.identity, Time.deltaTime * ReturnLookSpeed); } } }
void attachMagazine() { // Drop Item var grabber = HeldMagazine.GetPrimaryGrabber(); HeldMagazine.DropItem(grabber, false, false); // Play Sound VRUtils.Instance.PlaySpatialClipAt(ClipAttachSound, transform.position, 1f); // Move to desired location before locking in place moveMagazine(Vector3.zero); // Add fixed joint to make sure physics work properly if (transform.parent != null) { Rigidbody parentRB = transform.parent.GetComponent <Rigidbody>(); if (parentRB) { FixedJoint fj = HeldMagazine.gameObject.AddComponent <FixedJoint>(); fj.autoConfigureConnectedAnchor = true; fj.axis = new Vector3(0, 1, 0); fj.connectedBody = parentRB; } // If attached to a Raycast weapon, let it know we attached something if (parentWeapon) { parentWeapon.OnAttachedAmmo(); } } // Don't let anything try to grab the magazine while it's within the weapon // We will use a grabbable proxy to grab the clip back out instead HeldMagazine.enabled = false; lockedInPlace = true; magazineInPlace = true; }
void checkSecondaryLook() { // Create transform to look at if we are looking at a precise grab if (SecondaryGrabbable != null && SecondaryGrabbable.BeingHeld) { if (SecondaryLookAtTransform == null) { Grabber thisGrabber = GetPrimaryGrabber(); Grabber secondaryGrabber = SecondaryGrabbable.GetPrimaryGrabber(); GameObject o = new GameObject(); SecondaryLookAtTransform = o.transform; SecondaryLookAtTransform.name = "LookAtTransformTemp"; // Precise grab can use current grabber position if (SecondaryGrabbable.GrabMechanic == GrabType.Precise) { SecondaryLookAtTransform.position = secondaryGrabber.transform.position; } // Otherwise use snap point else { Transform grabPoint = SecondaryGrabbable.GetClosestGrabPoint(secondaryGrabber); if (grabPoint) { SecondaryLookAtTransform.position = grabPoint.position; } else { SecondaryLookAtTransform.position = SecondaryGrabbable.transform.position; } SecondaryLookAtTransform.position = SecondaryGrabbable.transform.position; } if (SecondaryLookAtTransform && thisGrabber) { SecondaryLookAtTransform.parent = thisGrabber.transform; SecondaryLookAtTransform.localEulerAngles = Vector3.zero; SecondaryLookAtTransform.localPosition = new Vector3(0, 0, SecondaryLookAtTransform.localPosition.z); // Move parent back to grabber SecondaryLookAtTransform.parent = secondaryGrabber.transform; } } } // We should not be aiming at anything if a Grabbable was specified if (SecondaryGrabbable != null && !SecondaryGrabbable.BeingHeld && SecondaryLookAtTransform != null) { clearLookAtTransform(); } Grabber heldBy = GetPrimaryGrabber(); if (heldBy) { Transform grabberTransform = heldBy.transform; if (SecondaryLookAtTransform != null) { // Can use this to offset look //var rotForwardToDown = Quaternion.FromToRotation(Vector3.forward, -Vector3.up); Vector3 initialRotation = grabberTransform.localEulerAngles; Quaternion dest = Quaternion.LookRotation(SecondaryLookAtTransform.position - grabberTransform.position, Vector3.up); grabberTransform.rotation = Quaternion.Slerp(grabberTransform.rotation, dest, Time.deltaTime * SecondHandLookSpeed); // Exclude rotations to only x and y grabberTransform.localEulerAngles = new Vector3(grabberTransform.localEulerAngles.x, grabberTransform.localEulerAngles.y, initialRotation.z); } else { grabberTransform.localEulerAngles = angleLerp(grabberTransform.localEulerAngles, GrabRotationOffset, Time.deltaTime * 20); } } }
void Update() { if (JoystickGrabbable != null) { if (JoystickGrabbable.BeingHeld) { Transform lookAt = JoystickGrabbable.GetPrimaryGrabber().transform; // Look towards the Grabber if (HingeXTransform) { originalRot = HingeXTransform.rotation; HingeXTransform.LookAt(lookAt, Vector3.left); angleX = HingeXTransform.localEulerAngles.x; if (angleX > 180) { angleX -= 360; } HingeXTransform.localEulerAngles = new Vector3(Mathf.Clamp(angleX, MinXAngle, MaxXAngle), 0, 0); if (UseSmoothLook) { Quaternion newRot = HingeXTransform.rotation; HingeXTransform.rotation = originalRot; HingeXTransform.rotation = Quaternion.Lerp(HingeXTransform.rotation, newRot, Time.deltaTime * SmoothLookSpeed); } } if (HingeYTransform) { originalRot = HingeYTransform.rotation; HingeYTransform.LookAt(lookAt, Vector3.left); angleY = HingeYTransform.localEulerAngles.y; if (angleY > 180) { angleY -= 360; } HingeYTransform.localEulerAngles = new Vector3(0, Mathf.Clamp(angleY, MinYAngle, MaxYAngle), 0); if (UseSmoothLook) { Quaternion newRot = HingeYTransform.rotation; HingeYTransform.rotation = originalRot; HingeYTransform.rotation = Quaternion.Lerp(HingeYTransform.rotation, newRot, Time.deltaTime * SmoothLookSpeed); } } } // Return to center if not being held else if (ReturnToCenterSpeed > 0) { if (HingeXTransform) { HingeXTransform.localRotation = Quaternion.Lerp(HingeXTransform.localRotation, Quaternion.identity, Time.deltaTime * ReturnToCenterSpeed); } if (HingeYTransform) { HingeYTransform.localRotation = Quaternion.Lerp(HingeYTransform.localRotation, Quaternion.identity, Time.deltaTime * ReturnToCenterSpeed); } } CallJoystickEvents(); } }