void Update() { //Directions obtained from CC_CANOE class. We use the Right wand and Head for orientation. //Where the right wand is pointed is the direction the player will move Vector3 forwardDir = CC_CANOE.WandGameObject(Wand.Right).transform.forward; Vector3 rightDir = CC_CANOE.HeadGameObject().transform.right; rightDir = Vector3.Normalize(Vector3.ProjectOnPlane(rightDir, Vector3.up)); Vector3 upDir = Vector3.up; //The input from the trigger axis of the left wand float forward = CC_INPUT.GetAxis(Wand.Right, WandAxis.Trigger); //Move the CharacterController attached to the CC_CANOE. Vector3 movement = forwardDir * forward; charCont.Move(movement * Time.deltaTime * moveSpeed); //The input from the X and Y axis of the right wand joystick. yAxisChange += CC_INPUT.GetAxis(Wand.Right, WandAxis.XAxis) * Time.deltaTime * lookSpeed; yAxisChange = yAxisChange % 360.0f; xAxisChange += CC_INPUT.GetAxis(Wand.Right, WandAxis.YAxis) * Time.deltaTime * lookSpeed; xAxisChange = Mathf.Clamp(xAxisChange, -maxPitch, maxPitch); //Change the direction the CharacterController is facing. charCont.transform.rotation = Quaternion.identity; charCont.transform.RotateAround(CC_CANOE.CanoeGameObject().transform.position, Vector3.up, yAxisChange); charCont.transform.RotateAround(CC_CANOE.CanoeGameObject().transform.position, rightDir, xAxisChange); }
/// <summary> /// Updates the values for the x, y, and angle variables using the GetAxis methods. /// </summary> private void updateTrackpad() { x = CC_INPUT.GetAxis(Wand.Left, WandAxis.XAxis) / 2; y = CC_INPUT.GetAxis(Wand.Left, WandAxis.YAxis) / 2; angle = Mathf.Atan2(y, x); if (angle < 0) { angle += (2 * Mathf.PI); } }
private void updateText(Wand wand, TextMesh mesh) { mesh.text = wand.ToString() + " Info\npos: " + tracker.GetWandPosition((int)wand) + "\nrot: " + tracker.GetWandRotation((int)wand); mesh.text += "\nmenu clicked ? " + CC_INPUT.GetButtonPress(wand, WandButton.Menu); mesh.text += "\ngrip clicked ? " + CC_INPUT.GetButtonPress(wand, WandButton.Grip); mesh.text += "\nx = " + CC_INPUT.GetAxis(wand, WandAxis.XAxis).ToString("0.00") + "\ny = " + CC_INPUT.GetAxis(wand, WandAxis.YAxis).ToString("0.00") + "\nclicked ? " + CC_INPUT.GetButtonPress(wand, WandButton.TrackpadClick); mesh.text += "\ntrigger axis = " + CC_INPUT.GetAxis(wand, WandAxis.Trigger).ToString("0.00") + "\ntrigger pulled ? " + CC_INPUT.GetButtonPress(wand, WandButton.Trigger); }
// Update is called once per frame void Update() { float angle = Mathf.Atan2(CC_INPUT.GetAxis(wand, WandAxis.YAxis), CC_INPUT.GetAxis(wand, WandAxis.XAxis)); if (angle < 0f) { angle += 2 * Mathf.PI; } angle = angle * (180f / Mathf.PI); if (CC_INPUT.GetButtonDown(wand, WandButton.TrackpadClick)) { if ((angle >= 45f) && (angle <= 135f)) { Debug.Log("Up object selected"); chosenParticles = upParticles; } else if ((angle >= 225f) && (angle <= 315f)) { Debug.Log("Down object selected"); chosenParticles = downParticles; } else if ((angle > 135f) && (angle < 225f)) { Debug.Log("Left object selected"); chosenParticles = leftParticles; } else if (((angle >= 0) && (angle < 45)) || ((angle > 315) && (angle <= 360f))) { Debug.Log("Right object selected"); chosenParticles = rightParticles; } tempParticles = Instantiate(chosenParticles, wandTransform.position, wandTransform.rotation); } if (CC_INPUT.GetButtonPress(wand, WandButton.TrackpadClick)) { tempParticles.transform.position = wandTransform.position; } if (CC_INPUT.GetButtonUp(wand, WandButton.TrackpadClick)) { tempParticles.AddComponent <DestroyProjectile>(); } }
void FixedUpdate() { if (!enableNavigation) { return; } //Save wand model savedWandModel = canoe.wandModel; //If we are using the trigger button to navigate check if it is pressed. if (navWithTrigger) { if (CC_INPUT.GetAxis(wandToUse, WandAxis.Trigger) > 0.0f) { doNav = true; endNavUpdated = false; } else { doNav = false; } } else { //Otherwise check the chosen wand button doNav = CC_INPUT.GetButtonPress(wandToUse, navButton); endNavUpdated = false; } if ((resetButton == navButton) && (!navWithTrigger)) { print("CCaux_OmniNavigator Warning: Chosen Navigation and Reset Navigation buttons are the same."); } //Gradually resets canoe position and rotation if (CC_INPUT.GetButtonPress(wandToUse, resetButton)) { charCont.transform.position = Vector3.Slerp(charCont.transform.position, resetPosition, resetSpeed * Time.deltaTime); charCont.transform.rotation = Quaternion.Slerp(charCont.transform.rotation, resetAngle, resetSpeed * Time.deltaTime); } //Disables the cursor and re-enables the wand models ONCE if (!doNav && !endNavUpdated) { doneNav = false; canoe.wandModel = savedWandModel; cursor.SetActive(false); canoe.UpdateWandModels(); endNavUpdated = true; } if (doNav) { // If wand button pressed the first time then record the starting position and orientation of the wand if (doneNav == false) { startPosition = CC_CANOE.WandGameObject(wandToUse).transform.localPosition; doneNav = true; startRotation = CC_CANOE.WandGameObject(wandToUse).transform.localRotation; } else { // Then at each time check the difference between new and old wand position as well as new and old wand orientation. // Apply that difference to the character controller to effect navigation. Vector3 movement = CC_CANOE.WandGameObject(wandToUse).transform.localPosition - startPosition; // If disable navigation in a particular axis is enabled then set movement values to zero. if (disableNavigationX) { movement.x = 0; } if (disableNavigationY) { movement.y = 0; } if (disableNavigationZ) { movement.z = 0; } movement = gameObject.transform.localRotation * movement; // Movement must take into account current orientation of CyberCANOE charCont.Move(movement * Time.deltaTime * moveSpeed); Quaternion newRotation = CC_CANOE.WandGameObject(wandToUse).transform.localRotation; // Check if a rotation lock is enabled and handle it float axisLockAngle; Quaternion rotator = new Quaternion(); switch (lockRotation) { case rotationLock.X: axisLockAngle = newRotation.eulerAngles.x; rotator.eulerAngles = new Vector3(axisLockAngle, 0, 0); startRotation.eulerAngles = new Vector3(startRotation.eulerAngles.x, 0, 0); break; case rotationLock.Y: axisLockAngle = newRotation.eulerAngles.y; rotator.eulerAngles = new Vector3(0, axisLockAngle, 0); startRotation.eulerAngles = new Vector3(0, startRotation.eulerAngles.y, 0); break; case rotationLock.Z: axisLockAngle = newRotation.eulerAngles.z; rotator.eulerAngles = new Vector3(0, 0, axisLockAngle); startRotation.eulerAngles = new Vector3(0, 0, startRotation.eulerAngles.z); break; default: rotator = newRotation; break; } charCont.transform.localRotation = charCont.transform.localRotation * Quaternion.Slerp(Quaternion.identity, Quaternion.Inverse(startRotation * Quaternion.Inverse(rotator)), Time.deltaTime * rotateSpeed); // If there is a cursor object then orient it with the wand position. if (cursor) { cursor.SetActive(true); cursor.transform.position = CC_CANOE.WandGameObject(wandToUse).transform.position; cursor.transform.rotation = CC_CANOE.WandGameObject(wandToUse).transform.rotation; canoe.DeactivateModels(); } } } }
void Update() { //Set grab setting grab = false; if (enableGrabbing) { if (grabWithTrigger) { if (CC_INPUT.GetAxis(wand, WandAxis.Trigger) > 0.0f) { grab = true; } else { grab = false; } } else { grab = CC_INPUT.GetButtonPress(wand, grabButton); } } if (grab) { if (grabbedObject == null) { if (currentObject != null) { grabbedObject = currentObject; // If object had a rigidbody, grabbed save the rigidbody's kinematic state // so it can be restored on release of the object Rigidbody body = null; body = grabbedObject.GetComponent <Rigidbody>(); if (body != null) { wasKinematic = body.isKinematic; body.isKinematic = true; } // Save away to original parentage of the grabbed object grabbedObjectParent = grabbedObject.transform.parent; // Make the grabbed object a child of the wand grabbedObject.transform.parent = CC_CANOE.WandGameObject(wand).transform; currentObject = null; // Disable collision between yourself and the grabbed object so that the grabbed object // does not apply its physics to you and push you off the world Physics.IgnoreCollision(CC_CANOE.CanoeCharacterController(), grabbedObject.GetComponent <Collider>(), true); } } } else { if (grabbedObject != null) { // Restore the original parentage of the grabbed object grabbedObject.transform.parent = grabbedObjectParent; // If object had a rigidbody, restore its kinematic state Rigidbody body = null; body = grabbedObject.GetComponent <Rigidbody>(); if (body != null) { body.isKinematic = wasKinematic; } //Re-enstate collision between self and object Physics.IgnoreCollision(CC_CANOE.CanoeCharacterController(), grabbedObject.GetComponent <Collider>(), false); grabbedObject = null; currentObject = null; } } }
// Update is called once per frame void Update() { Transform wandTransform = CC_CANOE.WandTransform(wand); Vector3 offset = new Vector3(wandTransform.position.x, wandTransform.position.y + verticalOffset, wandTransform.position.z); float angle = Mathf.Atan2(CC_INPUT.GetAxis(wand, WandAxis.YAxis), CC_INPUT.GetAxis(wand, WandAxis.XAxis)); if (angle < 0f) { angle += 2 * Mathf.PI; } angle = angle * (180f / Mathf.PI); if (CC_INPUT.GetButtonDown(wand, WandButton.TrackpadClick)) { if ((angle >= 45f) && (angle <= 135f)) { Debug.Log("Up object selected"); lanternObj = upObject; chosenButton = WandButton.Up; } else if ((angle >= 225f) && (angle <= 315f)) { Debug.Log("Down object selected"); lanternObj = downObject; chosenButton = WandButton.Down; } else if ((angle > 135f) && (angle < 225f)) { Debug.Log("Left object selected"); lanternObj = leftObject; chosenButton = WandButton.Left; } else if (((angle >= 0) && (angle < 45)) || ((angle > 315) && (angle <= 360f))) { Debug.Log("Right object selected"); lanternObj = rightObject; chosenButton = WandButton.Right; } } if (CC_INPUT.GetButtonDown(wand, WandButton.TrackpadClick)) { lanternObj.transform.localScale = Vector3.zero; Vector3 rotation = lanternObj.transform.eulerAngles; Quaternion quat = Quaternion.identity; lantern = Instantiate(lanternObj, offset, quat); lantern.gameObject.SetActive(true); lantern.transform.position = offset; } else if (CC_INPUT.GetButtonPress(wand, WandButton.TrackpadClick)) { lantern.transform.position = offset; } else if (CC_INPUT.GetButtonUp(wand, WandButton.TrackpadClick)) { lantern.GetComponent <Rigidbody>().isKinematic = false; lantern.GetComponent <Rigidbody>().AddForce(new Vector3(0, releaseForce, 0)); lantern.GetComponent <Lantern>().startExpiring = true; } }