void Release(ViveControllerModule module) { if (wrapper.isLocked) { return; } if (module.gameObject.GetComponent <FixedJoint>()) { // 2 module.gameObject.GetComponent <FixedJoint>().connectedBody = null; Destroy(module.gameObject.GetComponent <FixedJoint>()); // 3 // Debug.Log(module.Controller.velocity); rbody.velocity = module.Controller.velocity * 3; rbody.angularVelocity = module.Controller.angularVelocity; rbody.isKinematic = true; } Vector3 pos = guideTarget.transform.localPosition; Vector3 currentPos = this.transform.position; gameObject.GetComponentInChildren <AssetWrapper>().isHolding = false; switch (HandControllers.Instance.movementState) { case HandControllers.ACTIONTYPE.BASIC: //:TODO. this is a different mode; break; case HandControllers.ACTIONTYPE.MOVEX: currentPos.x += pos.x; break; case HandControllers.ACTIONTYPE.MOVEY: currentPos.y += pos.y; break; case HandControllers.ACTIONTYPE.MOVEZ: currentPos.z += pos.z; break; } //igal Vector3 targetPos = currentPos; LeanTween.move(gameObject, targetPos, 0.5f); //moving back on X only. LeanTween.moveLocal(guideTarget, guideCenter, 0.5f); //offset = Vector3.zero; grabbingModule = null; // collider.isTrigger = false; }
void FireWall(VREventData eventData) { //TODO: add haptic + visual feedback ViveControllerModule vive = (ViveControllerModule)eventData.module; vive.TriggerHapticPulse(.3f, 3999); Instantiate(wallPrefab, eventData.module.transform.position, eventData.module.transform.rotation); }
void Grab(ViveControllerModule module) { if (wrapper.isLocked) { return; } //Bind the module to this object. Debug.Log(HandControllers.Instance.movementState); //collider.isTrigger = true; grabbingModule = module; //Save the offset between the module and this object. Undo the current rotation of the module offset = transform.position - grabbingModule.transform.position; offset = Quaternion.Inverse(grabbingModule.transform.rotation) * offset; rotOffset = Quaternion.Inverse(grabbingModule.transform.rotation) * transform.rotation; //whenever you grap, save a offset position to move back and forth lockedoffset = grabbingModule.transform.position; targetpos = this.transform.position; // AxisLineRenderer axisrender = gameObject.GetComponentInChildren<AxisLineRenderer>(); guideTarget = wrapper.movementGuide; guideVisualCue = wrapper.visualCue; guideCenter = guideTarget.transform.localPosition; lockedAxis = guideTarget.transform.rotation; wrapper.isHolding = true; //Save the offset between the module and this object. Undo the current rotation of the module if (HandControllers.Instance.movementState == HandControllers.ACTIONTYPE.BASIC) { if (rbody) { var joint = AddFixedJoint(grabbingModule); joint.connectedBody = rbody; rbody.isKinematic = false; } } else { offset = transform.position - grabbingModule.transform.position; offset = Quaternion.Inverse(grabbingModule.transform.rotation) * offset; rotOffset = Quaternion.Inverse(grabbingModule.transform.rotation) * transform.rotation; } }
void Hold(ViveControllerModule module) { if (wrapper.isLocked) { return; } Vector3 diff = grabbingModule.transform.position - lockedoffset; Vector3 pos = guideTarget.transform.localPosition; switch (HandControllers.Instance.movementState) { case HandControllers.ACTIONTYPE.BASIC: //:TODO. this is a different mode; // lock the rotation as you move it freely, //so when you lock any axis they are still aligned moving in the right direction guideTarget.transform.rotation = lockedAxis; // Quaternion.Inverse(grabbingModule.transform.rotation); // lockedAxis; guideVisualCue.transform.rotation = lockedAxis; // break; case HandControllers.ACTIONTYPE.MOVEX: targetpos.x += (diff.x / 4); guideTarget.transform.localPosition = transform.InverseTransformPoint(targetpos); break; case HandControllers.ACTIONTYPE.MOVEY: targetpos.y += (diff.y / 4); guideTarget.transform.localPosition = transform.InverseTransformPoint(targetpos); break; case HandControllers.ACTIONTYPE.MOVEZ: targetpos.z += (diff.z / 4); guideTarget.transform.localPosition = transform.InverseTransformPoint(targetpos); break; } }