// Update is called once per frame void Update() { if (ViveInput.GetButtonDown(Hand, ViveButton.Grip)) { var count = Physics.OverlapSphereNonAlloc(transform.position, 0.04f, cols); for (int i = 0; i < count; i++) { var body = cols[i].GetComponent <Rigidbody>(); if (body != null) { attachedBodies.Add(body); body.isKinematic = true; body.transform.SetParent(transform); } } } if (ViveInput.GetButtonUp(Hand, ViveButton.Grip)) { for (int i = 0; i < attachedBodies.Count; i++) { var body = attachedBodies[i]; body.transform.SetParent(null); body.isKinematic = false; body.velocity = ViveInput.GetVelocity(Hand); body.angularVelocity = ViveInput.GetAngularVelocity(Hand); attachedBodies.RemoveAt(i); } } }
// Update is called once per frame void Update() { time += Time.deltaTime; if (ViveInput.GetTriggerValue(hand) > 0) { if (Physics.Raycast(transform.position, transform.right, out hit, 1000)) { line.SetPosition(1, Vector3.right * hit.distance); if (ViveInput.GetTriggerValue(hand) > 0.5) { // if (time >= TP_coolDown && gun_function == GUN_FUNCTION.Teleport_GUN && hit.collider.gameObject.layer == Mathf.Log(teleportLayer.value, 2)) if (time >= TP_coolDown && hit.collider.gameObject.layer == Mathf.Log(teleportLayer.value, 2)) { player.transform.position = hit.point; time = 0; // else if (time >= TP_coolDown && gun_function == GUN_FUNCTION.Telekinesis_GUN && hit.collider.gameObject.layer == Mathf.Log(grabLayer.value, 2)) } else if (hit.collider.gameObject.layer == Mathf.Log(grabLayer.value, 2)) { var rb = hit.collider.gameObject.GetComponent <Rigidbody>(); if (!rb) { return; } hit.collider.gameObject.layer = 0; grabbedBody = rb; grabbedBody.transform.SetParent(transform); grabbedBody.isKinematic = true; grabbedBody.useGravity = false; } } else if (grabbedBody) { hit.collider.gameObject.layer = LayerMask.NameToLayer("lift"); grabbedBody.transform.SetParent(null); grabbedBody.isKinematic = false; grabbedBody.useGravity = true; grabbedBody.velocity = ViveInput.GetVelocity(hand); grabbedBody.angularVelocity = ViveInput.GetAngularVelocity(hand); grabbedBody = null; } } else { line.SetPosition(1, Vector3.right * 10000); } } else { line.SetPosition(1, Vector3.zero); } }
// Update is called once per frame void Update() { if (grabedbody == null) { if (ViveInput.GetButtonDown(hand, ViveButton.Trigger)) { RaycastHit hit; Collider[] colider = Physics.OverlapSphere(ViveInput.GetPosition(hand), 0.09f); if (colider.Length > 0) { grabedbody = colider[0].GetComponent <Rigidbody>(); grabedbody.useGravity = false; grabedbody.isKinematic = true; } if (Physics.Raycast(ViveInput.GetPosition(hand), ViveInput.GetTransform(hand).forward, out hit)) { Debug.Log("here at raycast"); if (hit.rigidbody.gameObject.tag == "bowling_ball") { //var bullet= Instantiate(prefabinstition); // bullet.transform.position = hit.rigidbody.transform.position; Debug.Log("here with ball"); grabedbody = hit.rigidbody; grabedbody.useGravity = false; grabedbody.isKinematic = true; } // Destroy(prefabinstition); } } } else { grabedbody.transform.position = ViveInput.GetPosition(hand); grabedbody.transform.rotation = ViveInput.GetRotation(hand); if (ViveInput.GetButtonUp(hand, ViveButton.Trigger)) { grabedbody.angularVelocity = ViveInput.GetAngularVelocity(hand); grabedbody.velocity = ViveInput.GetVelocity(hand); grabedbody.isKinematic = false; grabedbody.useGravity = true; grabedbody = null; } } }
// Update is called once per frame void Update() { if (ViveInput.GetButtonDown(hand, ViveButton.Trigger)) { var numberOfColliders = Physics.OverlapSphereNonAlloc(transform.position, 0.05f, cols, grabLayer); if (numberOfColliders == 0) { return; } var rb = cols[0].GetComponent <Rigidbody>(); if (!rb) { return; } cols[0].gameObject.layer = 0; grabbedBody = rb; grabbedBody.transform.SetParent(transform); grabbedBody.isKinematic = true; grabbedBody.useGravity = false; } else if (ViveInput.GetButtonUp(hand, ViveButton.Trigger)) { if (!grabbedBody) { return; } cols[0].gameObject.layer = LayerMask.NameToLayer("lift"); grabbedBody.transform.SetParent(null); grabbedBody.isKinematic = false; grabbedBody.useGravity = true; grabbedBody.velocity = ViveInput.GetVelocity(hand); grabbedBody.angularVelocity = ViveInput.GetAngularVelocity(hand); grabbedBody = null; } }