//------------------------------------------------- protected virtual void OnAttachedToHand(Hand hand) { //Debug.Log("Pickup: " + hand.GetGrabStarting().ToString()); hadInterpolation = this.rigidbody.interpolation; attached = true; onPickUp.Invoke(); hand.HoverLock(null); rigidbody.interpolation = RigidbodyInterpolation.None; velocityEstimator.BeginEstimatingVelocity(); attachTime = Time.time; attachPosition = transform.position; attachRotation = transform.rotation; if (attachEaseIn) { attachEaseInTransform = hand.objectAttachmentPoint; } snapAttachEaseInCompleted = false; }
//------------------------------------------------- protected virtual void OnAttachedToHand(Hand hand) { //Debug.Log("<b>[SteamVR Interaction]</b> Pickup: " + hand.GetGrabStarting().ToString()); hadInterpolation = this.rigidbody.interpolation; attached = true; if (onPickUp != null) { onPickUp.Invoke(); } hand.HoverLock(null); rigidbody.interpolation = RigidbodyInterpolation.None; if (velocityEstimator != null) { velocityEstimator.BeginEstimatingVelocity(); } attachTime = Time.time; attachPosition = transform.position; attachRotation = transform.rotation; }
//------------------------------------------------- protected virtual void OnAttachedToHand(Hand hand) { GameObject focusedObject = this.gameObject; //Debug.Log("<b>[SteamVR Interaction]</b> Pickup: " + hand.GetGrabStarting().ToString()); //check if spawnerobject if (focusedObject.GetComponent <NewSpawner>()) { focusedObject = focusedObject.GetComponent <NewSpawner>().spawnObject(); } //apply variable grabbedObject = focusedObject; Grabbed = true; //Attach to Hand hadInterpolation = this.rigidbody.interpolation; attached = true; onPickUp.Invoke(); hand.HoverLock(null); rigidbody.interpolation = RigidbodyInterpolation.None; if (velocityEstimator != null) { velocityEstimator.BeginEstimatingVelocity(); } attachTime = Time.time; attachPosition = transform.position; attachRotation = transform.rotation; //add haircomponent if (grabbedObject.GetComponent <HairObject>() == null) { grabbedObject.AddComponent <HairObject>(); } //lock rigidbody but still exist for collission detection with head and hair grabbedObject.GetComponent <HairObject>().ToggleRigidBody(true, true); grabbedObject.GetComponent <HairObject>().Grabbed = true; grabbedObject.GetComponent <HairObject>().Hover = true; //update slider HSVColorPanel.instance.SelectedObject = grabbedObject; }
//------------------------------------------------- private void OnAttachedToHand(Hand hand) { attached = true; if (keyObjectScript != null) { keyObjectScript.currentHand = hand; keyObjectScript.SetHeld(hand); } onPickUp.Invoke(); hand.HoverLock(null); Rigidbody rb = GetComponent <Rigidbody>(); rb.isKinematic = true; rb.interpolation = RigidbodyInterpolation.None; if (hand.controller == null) { velocityEstimator.BeginEstimatingVelocity(); } attachTime = Time.time; attachPosition = transform.position; attachRotation = transform.rotation; if (attachEaseIn) { attachEaseInTransform = hand.transform; if (!Util.IsNullOrEmpty(attachEaseInAttachmentNames)) { float smallestAngle = float.MaxValue; for (int i = 0; i < attachEaseInAttachmentNames.Length; i++) { Transform t = hand.GetAttachmentTransform(attachEaseInAttachmentNames[i]); float angle = Quaternion.Angle(t.rotation, attachRotation); if (angle < smallestAngle) { attachEaseInTransform = t; smallestAngle = angle; } } } } snapAttachEaseInCompleted = false; }
//------------------------------------------------- protected virtual void OnAttachedToHand(Hand hand) { //if ( onAttachedToHand != null ) // onAttachedToHand.Invoke( hand ); attachedToHand = hand; hadInterpolation = rb.interpolation; attached = true; //onPickUp.Invoke(); hand.HoverLock(null); rb.interpolation = RigidbodyInterpolation.None; velocityEstimator.BeginEstimatingVelocity(); }
//------------------------------------------------- protected virtual void OnAttachedToHand(Hand hand) { hadInterpolation = this.rigidbody.interpolation; attached = true; onPickUp.Invoke(); hand.HoverLock(null); rigidbody.interpolation = RigidbodyInterpolation.None; velocityEstimator.BeginEstimatingVelocity(); attachTime = Time.time; attachPosition = transform.position; attachRotation = transform.rotation; }
//------------------------------------------------- protected virtual void OnAttachedToHand(Hand hand) { Debug.Log("<b>[SteamVR Interaction]</b> Pickup: " + hand.GetGrabStarting().ToString()); lastUsedHand = hand; hadInterpolation = this.rigidbody.interpolation; attached = true; onPickUp.Invoke(); if (!hoverLockIfGrabbed) { hand.HoverUnlock(null); } else { hand.HoverLock(null); } rigidbody.interpolation = RigidbodyInterpolation.None; velocityEstimator.BeginEstimatingVelocity(); attachTime = Time.time; attachPosition = transform.position; attachRotation = transform.rotation; if (hand.m_IndexFingerCollider != null) { hand.m_IndexFingerCollider.enabled = false; } if (dontLetGoOnInputUp) { m_inputUpIgnored = 0; } }
//------------------------------------------------- private void OnAttachedToHand(Hand hand) { float points = Time.time - lastHeld; Player playerInstance = Player.instance; GameController gc = playerInstance.gameObject.GetComponent <GameController>(); gc.AddPoints(points); GetComponent <Rigidbody>().isKinematic = false; GetComponent <Rigidbody>().detectCollisions = true; if (onAttachedToHand != null) { onAttachedToHand.Invoke(hand); } if (hand.controller == null) { velocityEstimator.BeginEstimatingVelocity(); } RumbleController(0.12f, 1500, hand); }
//------------------------------------------------- private void OnAttachedToHand(Hand hand) { attached = true; onPickUp.Invoke(); hand.HoverLock(null); ///////////////////////////////////////////////////// if (GetComponent <ActivateText>()) { GetComponent <ActivateText>().ShowText(); } if (GetComponent <Key>()) { GetComponent <Key>().KeyGrabbed(); return; } if (GetComponent <RequiredClue>()) { GetComponent <RequiredClue>().ObjectPickedUp(); } if (GetComponent <DestroyWhenPickedUp>()) { GetComponent <DestroyWhenPickedUp>().DestroyItem(); } if (GetComponent <ReturnToPositionAfterPickup>()) { GetComponent <ReturnToPositionAfterPickup>().StopReturning(); } ///////////////////////////////////////////////////// Rigidbody rb = GetComponent <Rigidbody>(); rb.isKinematic = true; rb.interpolation = RigidbodyInterpolation.None; if (hand.controller == null) { velocityEstimator.BeginEstimatingVelocity(); } attachTime = Time.time; attachPosition = transform.position; attachRotation = transform.rotation; if (attachEaseIn) { attachEaseInTransform = hand.transform; if (!Util.IsNullOrEmpty(attachEaseInAttachmentNames)) { float smallestAngle = float.MaxValue; for (int i = 0; i < attachEaseInAttachmentNames.Length; i++) { Transform t = hand.GetAttachmentTransform(attachEaseInAttachmentNames[i]); float angle = Quaternion.Angle(t.rotation, attachRotation); if (angle < smallestAngle) { attachEaseInTransform = t; smallestAngle = angle; } } } } snapAttachEaseInCompleted = false; }
void Update() { if ((SteamVR_Actions._default.GrabPinch.GetState(RightInputSource) || SteamVR_Actions._default.GrabPinch.GetState(LeftInputSource)) && attachedController == null && !introScene) { // Trigger pulled when frisbee not on hand => Recall if (SteamVR_Actions._default.GrabPinch.GetState(RightInputSource)) { attachedController = rightController; SoundManager.instance.PlayRecallRight(); } else { attachedController = leftController; SoundManager.instance.PlayRecallLeft(); } // Initialize the recall rigidbody.useGravity = false; recalling = true; recordingPos = false; //recallStartPosition = transform.position; recallStartTime = Time.time; // Clear velocity //rigidbody.velocity = Vector3.zero; // Also estimate the velocity velocityEstimator.BeginEstimatingVelocity(); FrisbeeSphere.material = recallMaterial; foreach (MeshRenderer renderer in frisbeeRim) { renderer.material = rimRecallMat; } } else if (introScene) { // Frisbee drifts towards player transform.position = Vector3.MoveTowards(transform.position, GameManager.S.player.transform.position, 0.01f); } else if (recalling && (SteamVR_Actions._default.GrabPinch.GetState(RightInputSource) || SteamVR_Actions._default.GrabPinch.GetState(LeftInputSource))) { // Non-physical recall Vector3 recallVector = attachedController.position - transform.position; rigidbody.MovePosition(transform.position + Vector3.Normalize(recallVector) * Mathf.Min(recallSpeed * Time.deltaTime * (Time.time - recallStartTime), recallVector.magnitude)); //rigidbody.MovePosition(Vector3.Lerp(recallStartPosition, attachedController.position, (Time.time - recallStartTime)/0.2f )); if (SteamVR_Actions._default.GrabPinch.GetState(RightInputSource)) { vibration.Execute(0.0f, 0.1f, 40.0f, 0.1f, RightInputSource); } else if (SteamVR_Actions._default.GrabPinch.GetState(LeftInputSource)) { vibration.Execute(0.0f, 0.1f, 40.0f, 0.1f, LeftInputSource); } } else if (recalling && !(SteamVR_Actions._default.GrabPinch.GetState(RightInputSource) || SteamVR_Actions._default.GrabPinch.GetState(LeftInputSource))) { // Recall cancelled (dropped) if (attachedController == rightController) { vibration.Execute(0.0f, 0.1f, 20.0f, 0.1f, RightInputSource); } else if (attachedController == leftController) { vibration.Execute(0.0f, 0.1f, 20.0f, 0.1f, LeftInputSource); } recalling = false; rigidbody.useGravity = true; attachedController = null; // Apply estimated velocity velocityEstimator.FinishEstimatingVelocity(); rigidbody.velocity = velocityEstimator.GetVelocityEstimate(); // Restore material FrisbeeSphere.material = originalMaterial; // foreach(MeshRenderer renderer in frisbeeRim){ // renderer.material = rimOriginalMat; // } for (int i = 0; i < frisbeeRim.Length; i++) { frisbeeRim[i].material = rimOriginalMats[i]; } } else if (!recalling && recordingPos) { frisbeePositions.Add(transform.position); } if (!(SteamVR_Actions._default.GrabPinch.GetState(RightInputSource) && attachedController == rightController) && !(SteamVR_Actions._default.GrabPinch.GetState(LeftInputSource) && attachedController == leftController) && attachedController != null) { // Throwing the frisbee frisbeePositions = new List <Vector3>(); frisbeePositions.Add(transform.position); recordingPos = true; transform.parent = null; attachedController = null; rigidbody.useGravity = true; rigidbody.isKinematic = false; // Apply velocity estimated by VelocityEstimator velocityEstimator.FinishEstimatingVelocity(); // Curve the frisbee towards the center float degreesFromCenter = Vector3.Angle(velocityEstimator.GetVelocityEstimate(), mainCamera.rotation.eulerAngles); if (degreesFromCenter < 45.0f) { Vector3 adjustedDirection = (degreesFromCenter / 45.0f) * velocityEstimator.GetVelocityEstimate().normalized + ((45.0f - degreesFromCenter) / 45.0f) * mainCamera.forward; rigidbody.velocity = adjustedDirection * velocityEstimator.GetVelocityEstimate().magnitude * 1.5f; } else { rigidbody.velocity = velocityEstimator.GetVelocityEstimate() * 1.5f; } rigidbody.angularVelocity = ScaleLocalAngularVelocity(velocityEstimator.GetAngularVelocityEstimate(), new Vector3(0.1f, 1.0f, 0.1f)); SoundManager.instance.PlayThrow(); gravityField.SetActive(true); } // if(!firstItemSuccess /*&& Tutorial.IsTutorial()*/ && GameManager.S.GetDestroyedScore() > 0){ // SoundManager.instance.PlayItemSucceed(); // firstItemSuccess = true; // } }