// Update is called once per frame void Update() { if (isGrabbed) { if (Vector3.Distance(hand.transform.position, anchor.position) < range) { Vector3 direction = transform.position - hand.transform.position; //Face towards target transform.rotation = Quaternion.FromToRotation(Vector3.down, direction); //Find difference between current anchor and the zero point //This is for distance comparison //You can then compare distance on seperate axis difference = zeroPoint.localPosition - anchor.localPosition; if (difference.x > xLimit || difference.x < -xLimit || difference.z > zLimit || difference.z < -zLimit) { if ((difference.x > xLimit * 2 || difference.x < -xLimit * 2 || difference.z > zLimit * 2 || difference.z < -zLimit * 2)) { handHaptics.Vibrate(VibrationForce.Hard); } else if (difference.x > xLimit * 1.5 || difference.x < -xLimit * 1.5 || difference.z > zLimit * 1.5 || difference.z < -zLimit * 1.5) { handHaptics.Vibrate(VibrationForce.Medium); } else { handHaptics.Vibrate(VibrationForce.Light); } } } } }
// U P D A T E void Update() { UpdateLastPosition(); GetController(); if (OVRInput.Get(OVRInput.Button.PrimaryHandTrigger, controller)) // when hand trigger is pressed { ///Debug.Log(Time.time + " - " controller_name + ": Hand Trigger is being Pressed"); handTriggerPressed = true; if (collisionHappenedFirst && holdingObject == null) { ////Debug.Log(Time.time + " - " + controller_name + " controller Trigger is pressed while colliding with " ///+ collidingObject.name); if (otherCC.holdingObject != null) // this is to check if the object about to hold is already held by the other hand { if (otherCC.holdingObject.transform.parent.gameObject == otherController_GO) { ///otherController_GO.GetComponent<ControllerCollision>().ReleaseObject(); ////Debug.Log("Taking over " + collidingObject.name + " from " + otherCC.controller_name + " controller"); otherCC.holdingObject.transform.parent = null; // if so, remove links of that object with previous controller otherCC.holdingObject = null; otherCC.holdingObject_rigidbody = null; otherCC.collisionHappenedFirst = false; otherCC.GetComponent <OculusHaptics>().Vibrate(VibrationForce.Light); ///otherCC.ReleaseObject(); } } holdingObject = collidingObject.gameObject; // // now take control of the object which was colliding holdingObject.transform.SetParent(gameObject.transform); holdingObject_rigidbody = holdingObject.GetComponent <Rigidbody>(); holdingObject_rigidbody.isKinematic = true; // turn off the physics of that object if (holdingObject.name == "Ball") // Reset the ball, this is to stop picking or catching ball after throwing { GL.ResetGame(); } haptics.Vibrate(VibrationForce.Light); /*Physics.IgnoreCollision(holdingObject.GetComponent<Collider>(), * player.GetComponent<Collider>());*/ ///Debug.Log(": Already Colliding, so Holding object"); } } else { /*if(handTriggerPressed && holdingObject != null) * Debug.Log(Time.time + ": Trigger Released");*/ handTriggerPressed = false; ReleaseObject(); // Rlease object when hand trigger is released } }
void Fire() { if (Physics.Raycast(ray, out hit)) { haptics.Vibrate(VibrationForce.Medium); GameObject particles = Instantiate(hitParticles, hit.point, Quaternion.identity); Destroy(particles, 0.4f); if (hit.collider.tag == "Enemy") { hit.collider.gameObject.GetComponent <EnemyBehaviours>().State = EnemyState.Dead; } if (hit.collider.tag == "score") { hit.collider.gameObject.GetComponent <EnemyDie>().Die(); } if (hit.collider.tag == "bullet") { Destroy(hit.collider.gameObject); } } GameObject trail = Instantiate(hitTrail); VolumetricLines.VolumetricLineBehavior vol = trail.GetComponent <VolumetricLines.VolumetricLineBehavior>(); vol.StartPos = barrellStart.position; vol.EndPos = barrelEnd.position; lazerShot.Play(); }
// Update is called once per frame void Update() { if (isGrabbed) { anchorRestricted.transform.position = hand.transform.position; Vector3 handToBase = anchorRestricted.localPosition - anchorBase.localPosition; Vector3 anchorToBase = anchor.localPosition - anchorBase.localPosition; float xDifference = VectorFunctions.PolarAngleToFrom(handToBase, anchorToBase); transform.Rotate(xDifference / movementSensetivity, 0, 0, Space.Self); float localX = transform.localEulerAngles.x; if (localX > 180) { localX = -360 + localX; } if (localX > rotationLimitPositive) { transform.Rotate(-xDifference / movementSensetivity, 0, 0, Space.Self); } else if (localX < rotationLimitNegative) { transform.Rotate(-xDifference / movementSensetivity, 0, 0, Space.Self); } difference = zeroPoint.localPosition - anchor.localPosition; if (difference.z > xLimit || difference.z < -zLimit) { if ((difference.z > zLimit * 2 || difference.z < -zLimit * 2)) { handHaptics.Vibrate(VibrationForce.Hard); } else if (difference.z > zLimit * 1.5 || difference.z < -zLimit * 1.5) { handHaptics.Vibrate(VibrationForce.Medium); } else { handHaptics.Vibrate(VibrationForce.Light); } } } }
public void OpenObjectSpawMenu(bool state) // only show object spawner menu when level starts { if (currentLevel != 0) { controllerInput.ObjSpawnMenu_SetActive(state); L_haptics.Vibrate(VibrationForce.Medium); } }
// TELEPORT PLAYER public void InitTeleportPlayer(Vector3 tLoc) // start teleporting only from level 1 and play audio before teleporting { if (currentLevel != 0 && sceneTransition == SceneTransition.complete) { player.InitTeleport(tLoc); playerSpeaker.clip = teleportAudio; playerSpeaker.Play(); R_haptics.Vibrate(VibrationForce.Medium); } }
void Fire() { if (ammo <= 0) { //Play CUCUCU GetComponent <AudioSource>().Play(); return; } haptics.Vibrate(VibrationForce.Hard); //StartCoroutine(haptics.VibrateTime(VibrationForce.Hard, 0.5f)); cooldown = reloadTime; ammo -= 1; var bullet = (Instantiate(this.bullet, transform.position, Quaternion.identity) as GameObject).GetComponent <Bullet>(); bullet.speed = bulletSpeed; bullet.direction = -transform.up; bullet.gun = this; }
// Update is called once per frame void Update() { OVRInput.Update(); log("->Update()!"); Transform root_anchor = camera_rig.trackingSpace; Transform centerEyeAnchor = camera_rig.centerEyeAnchor; Transform leftHandAnchor = camera_rig.leftHandAnchor; Transform rightHandAnchor = camera_rig.rightHandAnchor; Vector3 eye_P_right_hand = rightHandAnchor.position; // - center_eye_anchor.position; Quaternion rightHandQuat = rightHandAnchor.rotation; Quaternion leftHandQuat = leftHandAnchor.rotation; Quaternion headQuat = centerEyeAnchor.rotation; string msg; msg = string.Format("{0:N5}", -headQuat[2]) + ',' + string.Format("{0:N5}", headQuat[0]) + ',' + string.Format("{0:N5}", -headQuat[1]) + ',' + string.Format("{0:N5}", headQuat[3]); //msg = string.Format("{0:N5}", eye_P_right_hand[2]) + ',' + string.Format("{0:N5}", -eye_P_right_hand[0]) + ',' + string.Format("{0:N5}", eye_P_right_hand[1]) + ','; //msg += string.Format("{0:N5}", rightHandQuat[2]) + ',' + string.Format("{0:N5}", rightHandQuat[0]) + ',' + string.Format("{0:N5}", rightHandQuat[1]) + ',' + string.Format("{0:N5}", rightHandQuat[3]); //msg += string.Format("{0:N5}", -right_hand_quat[2]) + ',' + string.Format("{0:N5}", right_hand_quat[3]) + ',' + string.Format("{0:N5}", right_hand_quat[1]) + ',' + string.Format("{0:N5}", right_hand_quat[0]); log(msg); if (connectTCP) { //Debug.Log("tcp"); //Debug.Log(msg); tcp.writeSocket(msg); //String str = tcp.readSocket(); //Debug.Log(str); //Debug.Log(str.Length); //if (str.Equals("end")) { // Debug.Log("End"); // string data = string.Join("", dataList.ToArray()); // dataList.Clear(); // total = 0; // Debug.Log("Total length: "); // Debug.Log(data.Length); //} else { // if (str.Length != 0) { // total += str.Length; // Debug.Log(total); // dataList.Add(str); // } //} } //String s = tcpImage.readThread(); //if (s.Length != 0) { // Debug.Log("Length of image received: " + s.Length); // //Debug.Log("First letters: " + s.Substring(0, 20)); //} //if (connectUDP) { // string data = udp.readSocket(); // Debug.Log(data.Length); //} // haptics // WARNING: To get it working, you have to wear the headset or activate its proximity sensor!! if (OVRInput.Get(OVRInput.Button.One)) { Debug.Log("Button A pressed!"); haptics.Vibrate(VibrationForce.Light); } if (OVRInput.Get(OVRInput.Button.Two)) { Debug.Log("Button B pressed!"); haptics.Vibrate(VibrationForce.Medium); } if (OVRInput.Get(OVRInput.Button.Three)) { Debug.Log("Button X pressed!"); haptics.Vibrate(VibrationForce.Hard); } log(" Update()->"); }