// Update is called once per frame void Update() { //What is each hand pointing to? Physics.Raycast(left_hand_triplet.transform.position, left_hand_triplet.forward, out left_hand_raycast_hit, 50, player_complement_mask); Physics.Raycast(right_hand_triplet.transform.position, right_hand_triplet.forward, out right_hand_raycast_hit, 50, player_complement_mask); /* Spell code */ switch (current_spell) { /* --------------------------------- */ /* Similar to HL:A's Grabbity Gloves */ /* --------------------------------- */ case Spell.ATTRACT: { in_source_buffer = stvr_player.leftHand.handType; //If grip is pressed, change attraction target if (stvr_grip[in_source_buffer].stateDown && left_hand_raycast_hit.transform.tag == "ALLOW_MANIPULATION") { attr_left_target = left_hand_raycast_hit.transform; //Create and start particle system Transform tracker = Instantiate(grabbity_tracker, attr_left_target.position, Quaternion.Euler(0.0f, 0.0f, 0.0f)); tracker.SetParent(attr_left_target); } //Check for flick of left hand if (attr_left_target != null && Vector3.Dot(stvr_controller_pose[in_source_buffer].velocity, (Camera.main.transform.forward - Camera.main.transform.up)) < -attraction_spell_sensitivity) { //Calculate velocity and apply it to the target Vector3 calculated_velocity = ComplementarCalculations.CalculateParabola(attr_left_target.transform.position, left_hand_triplet.position); attr_left_target.GetComponent <Rigidbody>().velocity = calculated_velocity; //Destroy particle system Destroy(attr_left_target.GetChild(1).gameObject); attr_left_target = null; } in_source_buffer = stvr_player.rightHand.handType; //If grip is pressed, change attraction target if (stvr_grip[in_source_buffer].stateDown && right_hand_raycast_hit.transform.tag == "ALLOW_MANIPULATION") { attr_right_target = right_hand_raycast_hit.transform; //Create particle system Transform tracker = Instantiate(grabbity_tracker, attr_right_target.position, Quaternion.Euler(0.0f, 0.0f, 0.0f)); tracker.SetParent(attr_right_target); } //Check for flick of left hand if (attr_right_target != null && Vector3.Dot(stvr_controller_pose[in_source_buffer].velocity, (Camera.main.transform.forward - Camera.main.transform.up)) < -attraction_spell_sensitivity) { //Calculate velocity and apply it to the target Vector3 calculated_velocity = ComplementarCalculations.CalculateParabola(attr_right_target.transform.position, right_hand_triplet.position); attr_right_target.GetComponent <Rigidbody>().velocity = calculated_velocity; //Destroy particle system Destroy(attr_right_target.GetChild(1).gameObject); attr_right_target = null; } break; } default: break; } }
void Update() { //Before highlighting, save the default material if (leftSelectionTransform != null) { var leftSelectionRenderer = leftSelectionTransform.GetComponent <Renderer>(); leftSelectionRenderer.material = defaultMaterial; leftSelectionTransform = null; } if (rightSelectionTransform != null) { var rightSelectionRenderer = rightSelectionTransform.GetComponent <Renderer>(); rightSelectionRenderer.material = defaultMaterial; rightSelectionTransform = null; } //What is each hand pointing to? RaycastHit leftHandRaycastHit; Physics.Raycast(leftHand.transform.position, leftHand.forward, out leftHandRaycastHit, 150); RaycastHit rightHandRaycastHit; Physics.Raycast(rightHand.transform.position, rightHand.forward, out rightHandRaycastHit, 150); //Highlighting var leftHighlight = leftHandRaycastHit.transform; if (leftHandRaycastHit.transform.tag == "ALLOW_MANIPULATION") { var leftSelectionRenderer = leftHighlight.GetComponent <Renderer>(); if (leftSelectionRenderer != null) { leftSelectionRenderer.material = highlightedMaterial; } leftSelectionTransform = leftHighlight; } var rightHighlight = rightHandRaycastHit.transform; if (rightHandRaycastHit.transform.tag == "ALLOW_MANIPULATION") { var rightSelectionRenderer = rightHighlight.GetComponent <Renderer>(); if (rightSelectionRenderer != null) { rightSelectionRenderer.material = highlightedMaterial; } rightSelectionTransform = rightHighlight; } //Grabbing code switch (current_spell) { case Spell.ATTRACT: { in_source_buffer = player.leftHand.handType; //If button pressed, change attraction target if (grabObject.GetState(SteamVR_Input_Sources.LeftHand) && leftHandRaycastHit.transform.tag == "ALLOW_MANIPULATION") { attr_left_target = leftHandRaycastHit.transform; //Move and start particle system Transform tracker = Instantiate(gravity_tracker, attr_left_target.position, Quaternion.Euler(0.0f, 0.0f, 0.0f)); tracker.SetParent(attr_left_target); } //Check for flick of left hand //Debug.Log(Vector3.Dot(leftControllerPose[in_source_buffer].velocity.normalized, (Camera.main.transform.forward - Camera.main.transform.up).normalized)); if (attr_left_target != null && Vector3.Dot(leftControllerPose[in_source_buffer].velocity, (Camera.main.transform.forward - Camera.main.transform.up)) < -0.5) { //Calculate velocity and apply it to the target Vector3 calculate_velocity = ComplementarCalculations.CalculateParabola(attr_left_target.transform.position, leftHand.transform.position); attr_left_target.GetComponent <Rigidbody>().velocity = calculate_velocity; //Destroy particle system Destroy(attr_left_target.GetChild(0).gameObject); attr_left_target = null; } in_source_buffer = player.rightHand.handType; //If button pressed, change attraction target if (grabObject.GetState(SteamVR_Input_Sources.RightHand) && rightHandRaycastHit.transform.tag == "ALLOW_MANIPULATION") { attr_right_target = rightHandRaycastHit.transform; //Move and start particle system Transform tracker = Instantiate(gravity_tracker, attr_right_target.position, Quaternion.Euler(0.0f, 0.0f, 0.0f)); tracker.SetParent(attr_right_target); } //Check for flick of right hand if (attr_right_target != null && Vector3.Dot(rightControllerPose[in_source_buffer].velocity, (Camera.main.transform.forward - Camera.main.transform.up)) < -0.5) { //Calculate velocity and apply it to the target Vector3 calculate_velocity = ComplementarCalculations.CalculateParabola(attr_right_target.transform.position, rightHand.transform.position); attr_right_target.GetComponent <Rigidbody>().velocity = calculate_velocity; //Destroy particle system Destroy(attr_right_target.GetChild(0).gameObject); attr_right_target = null; } break; } } }
// Update is called once per frame void Update() { if (handDevice == null || !handDevice.isValid) { Init(); } //What is hand pointing to? //Physics.Raycast(handTransform.transform.position, handTransform.forward, out handRaycastHit, collisionVolume.GetComponent<MeshCollider>().bounds.size.x * collisionVolume.transform.localScale.x, player_complement_mask); /* Spell code */ switch (current_spell) { /* --------------------------------- */ /* Similar to HL:A's Grabbity Gloves */ /* --------------------------------- */ case Spell.ATTRACT: { if (!IsGripActivated(handDevice) && isGloveActivated) { isGloveActivated = false; } UpdateLineRenderer(); //If we trigger aiming at a valid target if (currentObjectFocused != null && IsGripActivated(handDevice) && !isGloveActivated) { //Create particle system particulesInstance = Instantiate(grabbityTracker, currentObjectFocused.transform.position, Quaternion.Euler(0.0f, 0.0f, 0.0f)); particulesInstance.SetParent(currentObjectFocused.transform); isGloveActivated = true; currentObjectActive = currentObjectFocused; } else if (!isGloveActivated && particulesInstance != null) { Destroy(particulesInstance.gameObject); particulesInstance = null; currentObjectActive = null; } //Check for flick of hand if (currentObjectActive != null && particulesInstance != null && Vector3.Dot(GetDeviceVelocity(handDevice), (xr_rig.cameraGameObject.transform.forward - xr_rig.cameraGameObject.transform.up)) < -attractionSpellSensitivity) { //Calculate velocity and apply it to the target Vector3 calculated_velocity = ComplementarCalculations.CalculateParabola(currentObjectActive.transform.position, handTransform.position); currentObjectFocused.GetComponent <Rigidbody>().velocity = calculated_velocity; //Destroy particle system if (particulesInstance != null) { Destroy(particulesInstance.gameObject); particulesInstance = null; currentObjectActive = currentObjectFocused = null; } } break; } default: break; } }