// Update is called once per frame void Update() { if (m_controller == null) { m_controller = SixenseInput.GetController(m_hand); } else { if (startingH == 999 || m_controller.GetButtonDown(SixenseButtons.ONE)) { startingH = m_controller.Rotation.eulerAngles.y; startingV = m_controller.Rotation.eulerAngles.x; } curH = -Mathf.DeltaAngle(m_controller.Rotation.eulerAngles.y, startingH); curV = -Mathf.DeltaAngle(m_controller.Rotation.eulerAngles.x, startingV); curH = curH > 30 ? 30 : curH; curH = curH < -30 ? -30 : curH; curV = curV > 30 ? 30 : curV; curV = curV < -30 ? -30 : curV; cursorX = (curH + 30) / 60; cursorY = (curV + 30) / 60; Quaternion rotation = Quaternion.identity; rotation.eulerAngles = new Vector3(curV, curH * 16 / 9, 0); transform.localRotation = rotation; Vector3 fwd = transform.TransformDirection(Vector3.forward); Debug.DrawRay(transform.position, fwd * 100, Color.green); //if (Physics.Raycast(transform.position, fwd, 10)) { // print("There is something in front of the object!"); //} if (m_controller.GetButtonDown(SixenseButtons.TRIGGER) && !dragging) { RaycastHit hit = new RaycastHit(); if (Physics.Raycast(transform.position, fwd, out hit, 100) && hit.rigidbody) { Debug.Log("Jacob is dumb"); dragging = true; target = hit.rigidbody; target.useGravity = false; prevRotation = m_controller.Rotation; prevPosition = (m_controller.Position); prevLSP = transform.position; } } if (m_controller.GetButton(SixenseButtons.TRIGGER) && dragging) { target.MovePosition(target.transform.position + transform.TransformDirection(m_controller.Position - prevPosition) / 10 + transform.position - prevLSP); prevLSP = transform.position; prevPosition = (m_controller.Position); } if (m_controller.GetButtonUp(SixenseButtons.TRIGGER) && dragging) { dragging = false; target.useGravity = true; } } }
void Update() { hydraRight = SixenseInput.Controllers[1]; hydraLeft = SixenseInput.Controllers[0]; if(hydraLeft.GetButtonDown(SixenseButtons.TRIGGER) || hydraRight.GetButtonDown(SixenseButtons.TRIGGER)) { if(buttonHighlited == "StartTut") { Application.LoadLevelAsync("Level_00"); keybindsUi.SetActive(true); this.GetComponentInParent<FadeOutOnLevelLoad>().fade(0.0f); } else if(buttonHighlited == "StartHub") { Application.LoadLevelAsync("hub"); keybindsUi.SetActive(true); this.GetComponentInParent<FadeOutOnLevelLoad>().fade(0.0f); } else if(buttonHighlited == "PiratesPart1") { Application.LoadLevelAsync("pirates"); keybindsUi.SetActive(true); this.GetComponentInParent<FadeOutOnLevelLoad>().fade(0.0f); } else if(buttonHighlited == "PiratesSchiebe") { Application.LoadLevelAsync("SchiebeRätselPart1"); keybindsUi.SetActive(true); this.GetComponentInParent<FadeOutOnLevelLoad>().fade(0.0f); } else if(buttonHighlited == "PiratesDark") { Application.LoadLevelAsync("BelowTheDeck"); keybindsUi.SetActive(true); this.GetComponentInParent<FadeOutOnLevelLoad>().fade(0.0f); } else if(buttonHighlited == "PiratesPart2") { Application.LoadLevelAsync("pirates"); manager.pirateLevelPartTwo = true; keybindsUi.SetActive(true); this.GetComponentInParent<FadeOutOnLevelLoad>().fade(0.0f); } else if(buttonHighlited == "PiratesSchiebe2") { Application.LoadLevelAsync("SchieberätselPart2"); keybindsUi.SetActive(true); this.GetComponentInParent<FadeOutOnLevelLoad>().fade(0.0f); } else if(buttonHighlited == "Exit") { Application.Quit(); } } }
void Update() { jump = false; if (characterController == null || !characterController.grounded) { return; } if ((Input.GetButtonDown("Jump") || JumpGestureTriggered())) { shouldJump = true; } if (useRazerHydra) { razerController = SixenseInput.GetController(razerHydraID); if (razerController != null && razerController.Enabled) { if (razerController.GetButtonDown(SixenseButtons.BUMPER)) { shouldJump = true; } } } // Check if jumping with PS Move Navigation controller if (usePSNavigationController && moveWrapper && moveWrapper.isConnected) { if (PSNaviControllerID <= moveWrapper.navConnected.Length && PSNaviControllerID >= 1) { if (moveWrapper.navConnected[PSNaviControllerID - 1]) { if (moveWrapper.WasPressed(PSNaviControllerID - 1, "NavL1")) { shouldJump = true; } } } } if (shouldJump) { jump = true; } }
protected virtual void UpdateObject(SixenseInput.Controller controller) { if (controller.GetButtonDown(SixenseButtons.START)) { // enable position and orientation control m_enabled = !m_enabled; // delta controller position is relative to this point m_baseControllerPosition = new Vector3(controller.Position.x * Sensitivity.x, controller.Position.y * Sensitivity.y, controller.Position.z * Sensitivity.z); // this is the new start position m_initialPosition = this.gameObject.transform.localPosition; } if (m_enabled) { UpdatePosition(controller); UpdateRotation(controller); } }
public override bool SelectionButtonWasPressed() { if (razer == null || !razer.Enabled) { return(false); } switch (selectionButton) { case SixenseButtons.BUMPER: return(razer.GetButtonDown(SixenseButtons.BUMPER)); case SixenseButtons.FOUR: return(razer.GetButtonDown(SixenseButtons.FOUR)); case SixenseButtons.JOYSTICK: return(razer.GetButtonDown(SixenseButtons.JOYSTICK)); case SixenseButtons.ONE: return(razer.GetButtonDown(SixenseButtons.ONE)); case SixenseButtons.START: return(razer.GetButtonDown(SixenseButtons.START)); case SixenseButtons.THREE: return(razer.GetButtonDown(SixenseButtons.THREE)); case SixenseButtons.TRIGGER: return(razer.GetButtonDown(SixenseButtons.TRIGGER)); case SixenseButtons.TWO: return(razer.GetButtonDown(SixenseButtons.TWO)); default: return(false); } }
// Update is called once per frame void Update() { if (controller == null) { controller = this.gameObject.GetComponent <SixenseHand>().m_controller; } if (controller != null && curObject != null && curObject.GetComponent <Rigidbody>() != null && (controller.GetButtonDown(SixenseButtons.TRIGGER))) { Debug.Log("trying"); curObject.transform.parent = this.transform; curObject.GetComponent <Rigidbody>().useGravity = false; curObject.GetComponent <Rigidbody>().freezeRotation = true; } if (controller != null && curObject != null && curObject.GetComponent <Rigidbody>() != null && (controller.GetButtonUp(SixenseButtons.TRIGGER))) { curObject.transform.parent = null; curObject.GetComponent <Rigidbody>().useGravity = true; curObject.GetComponent <Rigidbody>().freezeRotation = false; curObject = null; } if (curObject != null && curObject.GetComponent <Rigidbody>() != null) { curObject.GetComponent <Rigidbody>().useGravity = false; } }
void Update() { jump = false; if(characterController == null || !characterController.grounded) return; if ((Input.GetButtonDown("Jump") || JumpGestureTriggered())) { shouldJump = true; } if(useRazerHydra) { razerController = SixenseInput.GetController(razerHydraID); if(razerController != null && razerController.Enabled) { if(razerController.GetButtonDown(SixenseButtons.BUMPER)) shouldJump = true; } } // Check if jumping with PS Move Navigation controller if (usePSNavigationController && moveWrapper && moveWrapper.isConnected) { if (PSNaviControllerID <= moveWrapper.navConnected.Length && PSNaviControllerID >= 1) { if (moveWrapper.navConnected[PSNaviControllerID-1]) { if(moveWrapper.WasPressed(PSNaviControllerID-1, "NavL1")) { shouldJump = true; } } } } if (shouldJump) { jump = true; } }
// Update is called once per frame void Update() { if (VRSettings.enabled == true) { angles = InputTracking.GetLocalRotation(VRNode.Head); hands.transform.rotation = Quaternion.Euler(0, angles.eulerAngles.y + 90.0f, 0); } else { hands.transform.rotation = Quaternion.Euler(0, cam.transform.eulerAngles.y + 90.0f, 0); } //This test must always be done if (leftController == null || rightController == null) { leftController = SixenseInput.GetController(SixenseHands.LEFT); rightController = SixenseInput.GetController(SixenseHands.RIGHT); } if ((leftController != null && leftController.Enabled) || (rightController != null && rightController.Enabled)) { if ((leftController.GetButton(SixenseButtons.THREE) || rightController.GetButton(SixenseButtons.FOUR)) && tag == "Unselected") { gameObject.GetComponent <MeshRenderer> ().enabled = true; } if ((leftController.GetButton(SixenseButtons.THREE) || rightController.GetButton(SixenseButtons.FOUR)) && grabbedObject != null) { grabbedObject.transform.position = newPos; grabbedObject = null; } if ((leftController.GetButton(SixenseButtons.THREE) || rightController.GetButton(SixenseButtons.FOUR)) && (tag == "Selected" || transform.position != originalPos)) { //Moves to original father transform.parent = originalFather.transform; //Moves to original position transform.position = originalPos; //Changes tag tag = "Unselected"; gameObject.GetComponent <Renderer> ().material.color = startColor; gameObject.GetComponent <MeshRenderer> ().enabled = true; //Returns rotation to original father if (originalFather.GetComponent("RotObj") as RotObj == null) { originalFather.AddComponent <RotObj> (); } } if (leftController.GetButtonDown(SixenseButtons.TRIGGER) && gameObject.GetComponent <Renderer> ().material.color == Color.magenta) { //Saves original position newPos = transform.position; //Saves original scale originalScale = transform.localScale; transform.parent = lefthandFather.transform; grabbedObject = this.gameObject; grabbedObject.transform.localScale = originalScale - new Vector3(2.0f, 2.0f, 2.0f); grabbedObject.GetComponent <Renderer> ().material.color = startColor; Destroy(originalFather.GetComponent <RotObj> ()); } if (leftController.GetButtonUp(SixenseButtons.TRIGGER) && grabbedObject != null) { grabbedObject.transform.parent = originalFather.transform; grabbedObject.transform.localScale = originalScale; //grabbedObject.tag = "Unselected"; if (originalFather.GetComponent("RotObj") as RotObj == null) { originalFather.AddComponent <RotObj> (); } } if (rightController.GetButtonDown(SixenseButtons.TRIGGER) && gameObject.GetComponent <Renderer> ().material.color == Color.magenta) { //Saves original position newPos = transform.position; //Saves original scale originalScale = transform.localScale; transform.parent = righthandFather.transform; grabbedObject = this.gameObject; grabbedObject.transform.localScale = originalScale - new Vector3(2.0f, 2.0f, 2.0f); grabbedObject.GetComponent <Renderer> ().material.color = startColor; Destroy(originalFather.GetComponent <RotObj> ()); } if (rightController.GetButtonUp(SixenseButtons.TRIGGER) && grabbedObject != null) { grabbedObject.transform.parent = originalFather.transform; grabbedObject.transform.localScale = originalScale; //grabbedObject.tag = "Unselected"; if (originalFather.GetComponent("RotObj") as RotObj == null) { originalFather.AddComponent <RotObj> (); } } } }
// Update is called once per frame void Update() { if(Input.GetKeyDown("2")) { GetComponent<ShieldController>().riseShield(); } if (projectilePowerIsActive > 0 && Input.GetKeyDown("1") /*hand.GetComponent<Transform>().rotation.x < 0.5*/) { if (!GetComponentInChildren<ShootProjectile>().getThrowed()) { GetComponentInChildren<ShootProjectile>().sendProjectile(); projectilePowerIsActive--; soundGoalSource.Play(); } } m_controller = SixenseInput.GetController(SixenseHands.LEFT); if (/*m_controller.GetButtonDown(SixenseButtons.TRIGGER)*/Input.GetKeyDown("3")) { if (ballTrapPowerIsActive > 0 && !ball.GetComponent<Control>().trapmat ) { ballTrapPowerIsActive--; ball.GetComponent<Control>().setTrap(); } } if (blurVision) { if (resetTimer) { GetComponentInChildren<UnityStandardAssets.ImageEffects.Blur>().enabled = true; startTime = Time.time; resetTimer = false; } currentTimer = 5.0f - (Time.time - startTime); if (startTime + 5.0f < Time.time) { GetComponentInChildren<UnityStandardAssets.ImageEffects.Blur>().enabled = false; resetTimer = true; blurVision = false; } } if (shieldPowerIsActive > 0 && /*Input.GetKeyDown("2")*/m_controller.GetButtonUp(SixenseButtons.ONE)) { if ((hand.GetComponent<Transform>().position.y - initialPosition) > 0.1) { GetComponent<ShieldController>().riseShield(); shieldPowerIsActive--; } } if (terrainPowerIsActive > 0 && /*Input.GetKeyDown("2")*/m_controller.GetButtonUp(SixenseButtons.TWO)) { if(localPointTerrainRaycasting.Equals(NULL_VECTOR3)) localPointTerrainRaycasting = GetComponent<RayCasting>().sendRaycast(); if ( !localPointTerrainRaycasting.Equals(NULL_VECTOR3) &&((hand.GetComponent<Transform>().position.y - initialPosition) > 0.1)) { GetComponent<RaiseLowerTerrain>().riseController(localPointTerrainRaycasting); terrainPowerIsActive--; localPointTerrainRaycasting = NULL_VECTOR3; Debug.Log("raiseterrain"); } } if(m_controller.GetButtonDown(SixenseButtons.ONE)) { initialPosition = hand.GetComponent<Transform>().position.y; } if (m_controller.GetButtonDown(SixenseButtons.TWO)) { initialPosition = hand.GetComponent<Transform>().position.y; Debug.Log(initialPosition); } if (m_controller.GetButtonDown(SixenseButtons.FOUR)) { initialRotation = hand.GetComponent<Transform>().rotation.x; } }
// Update is called once per frame void Update() { //get the controller for both hands if (leftController == null || rightController == null) { leftController = SixenseInput.GetController(SixenseHands.LEFT); rightController = SixenseInput.GetController(SixenseHands.RIGHT); } if ((leftController != null && leftController.Enabled) && (rightController != null && rightController.Enabled)) { //Aim for left hand //handLeft.AddComponent<LineRenderer> (); //LineRenderer lineLeft = handLeft.GetComponent <LineRenderer> (); //lineLeft.SetVertexCount (2); //lineLeft.SetWidth (0.1f, 0.25f); //lineLeft.enabled = true; //lineLeft.SetColors (Color.green, Color.green); lineLeft.SetPosition(0, pointerLeft.transform.position); lineLeft.SetPosition(1, pointerLeft.transform.TransformDirection(Vector3.forward) * 1000.0f); //Aim for right hand //handRight.AddComponent<LineRenderer> (); //LineRenderer lineRight = handRight.GetComponent <LineRenderer> (); //lineRight.SetVertexCount (2); //lineRight.SetWidth (0.1f, 0.25f); //lineRight.enabled = true; //lineRight.SetColors (Color.green, Color.green); lineRight.SetPosition(0, pointerRight.transform.position); lineRight.SetPosition(1, pointerRight.transform.TransformDirection(Vector3.forward) * 1000.0f); if (leftController.GetButtonDown(SixenseButtons.TWO)) { Vector3 directionLeft = pointerLeft.transform.TransformDirection(Vector3.forward) * 1000.0f; RaycastHit hit; if (Physics.Raycast(pointerLeft.transform.position, directionLeft, out hit)) { //Deselect if (hit.collider.gameObject.GetComponent <Renderer> ().material.color == Color.magenta) { switch (hit.collider.gameObject.name) { case "Carbon": hit.collider.gameObject.GetComponent <Renderer> ().material.color = carbonColor; break; case "Oxygen": hit.collider.gameObject.GetComponent <Renderer> ().material.color = oxygenColor; break; case "Nitrogen": hit.collider.gameObject.GetComponent <Renderer> ().material.color = nitrogenColor; break; case "Hydrogen": hit.collider.gameObject.GetComponent <Renderer> ().material.color = hydrogenColor; break; case "Iron": hit.collider.gameObject.GetComponent <Renderer> ().material.color = ironColor; break; case "Sulfur": hit.collider.gameObject.GetComponent <Renderer> ().material.color = sulfurColor; break; case "Phosphorus": hit.collider.gameObject.GetComponent <Renderer> ().material.color = phosphorusColor; break; } numError++; hit.collider.gameObject.tag = "Unselected"; } else { switch (hit.collider.gameObject.name) { case "Carbon": carbonColor = hit.collider.gameObject.GetComponent <Renderer> ().material.color; break; case "Oxygen": oxygenColor = hit.collider.gameObject.GetComponent <Renderer> ().material.color; break; case "Nitrogen": hydrogenColor = hit.collider.gameObject.GetComponent <Renderer> ().material.color; break; case "Hydrogen": nitrogenColor = hit.collider.gameObject.GetComponent <Renderer> ().material.color; break; case "Iron": ironColor = hit.collider.gameObject.GetComponent <Renderer> ().material.color; break; case "Sulfur": sulfurColor = hit.collider.gameObject.GetComponent <Renderer> ().material.color; break; case "Phosphorus": phosphorusColor = hit.collider.gameObject.GetComponent <Renderer> ().material.color; break; } hit.collider.gameObject.GetComponent <Renderer> ().material.color = Color.magenta; hit.collider.gameObject.tag = "Selected"; selected = hit.collider.gameObject; } } } if (rightController.GetButtonDown(SixenseButtons.ONE)) { Vector3 directionRight = pointerRight.transform.TransformDirection(Vector3.forward) * 1000.0f; RaycastHit hit; if (Physics.Raycast(pointerRight.transform.position, directionRight, out hit)) { //Deselect if (hit.collider.gameObject.GetComponent <Renderer> ().material.color == Color.magenta) { switch (hit.collider.gameObject.name) { case "Carbon": hit.collider.gameObject.GetComponent <Renderer> ().material.color = carbonColor; break; case "Oxygen": hit.collider.gameObject.GetComponent <Renderer> ().material.color = oxygenColor; break; case "Nitrogen": hit.collider.gameObject.GetComponent <Renderer> ().material.color = nitrogenColor; break; case "Hydrogen": hit.collider.gameObject.GetComponent <Renderer> ().material.color = hydrogenColor; break; case "Iron": hit.collider.gameObject.GetComponent <Renderer> ().material.color = ironColor; break; case "Sulfur": hit.collider.gameObject.GetComponent <Renderer> ().material.color = sulfurColor; break; case "Phosphorus": hit.collider.gameObject.GetComponent <Renderer> ().material.color = phosphorusColor; break; } numError++; hit.collider.gameObject.tag = "Unselected"; } else { switch (hit.collider.gameObject.name) { case "Carbon": carbonColor = hit.collider.gameObject.GetComponent <Renderer> ().material.color; break; case "Oxygen": oxygenColor = hit.collider.gameObject.GetComponent <Renderer> ().material.color; break; case "Nitrogen": hydrogenColor = hit.collider.gameObject.GetComponent <Renderer> ().material.color; break; case "Hydrogen": nitrogenColor = hit.collider.gameObject.GetComponent <Renderer> ().material.color; break; case "Iron": ironColor = hit.collider.gameObject.GetComponent <Renderer> ().material.color; break; case "Sulfur": sulfurColor = hit.collider.gameObject.GetComponent <Renderer> ().material.color; break; case "Phosphorus": phosphorusColor = hit.collider.gameObject.GetComponent <Renderer> ().material.color; break; } hit.collider.gameObject.GetComponent <Renderer> ().material.color = Color.magenta; hit.collider.gameObject.tag = "Selected"; selected = hit.collider.gameObject; } } } } //Highlight atoms if ((leftController.GetButton(SixenseButtons.FOUR) || rightController.GetButton(SixenseButtons.THREE)) && selected != null) { foreach (GameObject atom in GameObject.FindGameObjectsWithTag("Unselected")) { if (atom.name != selected.gameObject.name) { atom.GetComponent <MeshRenderer> ().enabled = false; } else if (atom.name == selected.gameObject.name) { atom.tag = "Selected"; } } } }
// Update is called once per frame void Update() { //get the controller for both hands if (leftController == null || rightController == null) { leftController = SixenseInput.GetController(SixenseHands.LEFT); rightController = SixenseInput.GetController(SixenseHands.RIGHT); } if ((leftController != null && leftController.Enabled) && (rightController != null && rightController.Enabled)) { if (leftController.GetButtonDown(SixenseButtons.TWO)) { twoLeft++; } if (leftController.GetButtonDown(SixenseButtons.THREE)) { threeLeft++; } if (leftController.GetButtonDown(SixenseButtons.FOUR)) { fourLeft++; } if (leftController.GetButtonDown(SixenseButtons.BUMPER)) { bumperLeft++; } if (leftController.GetButtonDown(SixenseButtons.TRIGGER)) { triggerLeft++; } if (rightController.GetButtonDown(SixenseButtons.ONE)) { oneRight++; } if (rightController.GetButtonDown(SixenseButtons.FOUR)) { fourRight++; } if (rightController.GetButtonDown(SixenseButtons.THREE)) { threeRight++; } if (rightController.GetButtonDown(SixenseButtons.BUMPER)) { bumperRight++; } if (rightController.GetButtonDown(SixenseButtons.TRIGGER)) { triggerRight++; } } if (final.tag == "Completed") { passed = true; } //Player position totalDistance += Vector3.Distance(player.transform.position, lastPos); lastPos = player.transform.position; //Hand Position totalHandDistance += Vector3.Distance(player.transform.position, lastHandPos); lastHandPos = hand.transform.position; //Camera postion totalCamDistance += Vector3.Angle(cam.transform.localEulerAngles, camLastPos); camLastPos = cam.transform.localEulerAngles; if (Input.GetKeyDown(KeyCode.T) && activeScene != "tutorial") { //Add errors before recording data; unselectErrors.numError += threeLeft + fourRight; WriteFile(); UnityEditor.EditorApplication.isPlaying = false; } }
void Update() { #if UNITY_ANDROID if (getTouchTap() > 0.0f) { #else if (rightHydra.GetButtonDown(SixenseButtons.TRIGGER) || leftHydra.GetButtonDown(SixenseButtons.TRIGGER) || Input.GetAxis("Jump") > 0.0f) { #endif if (b_landed) { f_startSpeed = 0.75f; } b_collision = false; f_sprint = 0.5f; b_landed = false; rigidBody.constraints = RigidbodyConstraints.FreezeRotation; rigidBody.useGravity = false; anim.Play("BirtFlap2"); } if (leftHydra.GetButtonDown(SixenseButtons.START)) { resetGame(); } if (rightHydra.GetButtonDown(SixenseButtons.START) || Input.GetKeyDown(KeyCode.V) || Input.GetKeyDown(KeyCode.JoystickButton6)) { changeCameraPerspective(); } } void FixedUpdate() { if (f_startSpeed > 0.0f) { this.transform.position = new Vector3(this.transform.position.x, this.transform.position.y + f_startSpeed, this.transform.position.z); f_startSpeed -= 0.01f; } RotateX(leftHydra, rightHydra); RotateY(leftHydra, rightHydra); CalculateSpeed(leftHydra, rightHydra); } float getTouchTap() { foreach (Touch touch in Input.touches) { if (touch.phase == TouchPhase.Began) { f_timeSinceLastTouch = 1.0f; } } f_timeSinceLastTouch -= Time.deltaTime; return(f_timeSinceLastTouch); } void changeCameraPerspective() { if (b_firstperson) { cameras.transform.localPosition = new Vector3(0.0f, 7.0f, -19.0f); b_firstperson = false; schnabel.gameObject.SetActive(false); } else { cameras.transform.localPosition = new Vector3(0.0f, 0.0f, 3.7f); b_firstperson = true; schnabel.gameObject.SetActive(true); } } void resetGame() { b_landed = true; this.transform.position = new Vector3(0.0f, 352.0f, 0.0f); this.transform.rotation = Quaternion.Euler(new Vector3(0.0f, 0.0f, 0.0f)); playerModel.transform.localRotation = Quaternion.Euler(new Vector3(0.0f, 0.0f, 0.0f)); } void OnCollisionEnter(Collision info) { if (info.collider.gameObject.name == "worldborder") { this.transform.Rotate(new Vector3(0.0f, 180.0f, 0.0f)); this.transform.rotation = Quaternion.Euler(new Vector3(0.0f, this.transform.rotation.y, this.transform.rotation.z)); } else if (info.gameObject.transform.parent != null) { if (info.gameObject.transform.parent.gameObject.transform.parent != null) { if (info.gameObject.transform.parent.gameObject.transform.parent.name == "terrain") { if (!b_landed) { RaycastHit hit; Physics.Raycast(new Vector3(this.transform.position.x, this.transform.position.y, this.transform.position.z), new Vector3(0, -1, 0), out hit); if (Vector3.Dot(new Vector3(0, -1, 0), hit.normal) < -0.5f) { this.transform.rotation = Quaternion.Euler(new Vector3(0.0f, this.transform.rotation.eulerAngles.y, this.transform.rotation.eulerAngles.z)); this.transform.position = new Vector3(hit.point.x, hit.point.y + 1.0f, hit.point.z); b_landed = true; Debug.Log("landed"); rigidBody.useGravity = true; rigidBody.constraints = RigidbodyConstraints.None | RigidbodyConstraints.FreezeRotation; } } } } } } void RotateX(SixenseInput.Controller leftHydra, SixenseInput.Controller rightHydra) { if (!b_landed) { float xRot = 0.0f; float inputRotationX; if (b_keyboard) { inputRotationX = Input.GetAxis("Vertical") / 4.0f; } else if (b_mobile) { inputRotationX = -(Input.acceleration.z + 0.7f) / 2.0f; } else { inputRotationX = (rightHydra.Rotation.x + leftHydra.Rotation.x) / 2.0f; } if (transform.rotation.eulerAngles.x < 180) { xRot = Mathf.Clamp((transform.rotation.eulerAngles.x + (inputRotationX * 4)), -1.0f, 85.0f); } else { xRot = Mathf.Clamp((transform.rotation.eulerAngles.x + (inputRotationX * 4)), 275.0f, 361.0f); } Vector3 rotation = new Vector3(xRot, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z); transform.rotation = Quaternion.Euler(rotation); playerModel.transform.localRotation = Quaternion.Euler(new Vector3(xRot, playerModel.transform.rotation.eulerAngles.y, playerModel.transform.rotation.eulerAngles.z)); } } void RotateY(SixenseInput.Controller leftHydra, SixenseInput.Controller rightHydra) { float hydraDifference; if (b_keyboard) { hydraDifference = Input.GetAxis("Horizontal") * 45.0f; } else if (b_mobile) { hydraDifference = Input.acceleration.x * 85.0f; } else { hydraDifference = Mathf.Clamp(leftHydra.Position.y - rightHydra.Position.y, -75.0f, 75.0f); } transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + new Vector3(0, hydraDifference / 40.0f, 0)); playerModel.transform.localRotation = Quaternion.Euler(new Vector3(0, 0, -(hydraDifference))); } void CalculateSpeed(SixenseInput.Controller leftHydra, SixenseInput.Controller rightHydra) { float rotationXNorm = transform.rotation.eulerAngles.x / 360.0f; float gravityForce = -(f_speed) / 5; //runter if (rotationXNorm > 0.01 && rotationXNorm < 0.25) { f_speed += Map(0.0f, 0.010f, 0.0f, 0.25f, rotationXNorm); } //hoch else if (rotationXNorm > 0.75f && rotationXNorm < 0.99f) { f_speed += Map(-0.001f, 0, 0.75f, 1.0f, rotationXNorm); } f_speed = Mathf.Clamp(f_speed, 0.1f, 0.25f); Vector3 forward = new Vector3(0, 0, f_speed + f_sprint); f_sprint -= 0.0005f; f_speed -= 0.0005f; f_sprint = Mathf.Clamp(f_sprint, 0, 0.25f); Vector3 gravity = transform.position; gravity.y = gravity.y + gravityForce; if (!b_landed) { if (!b_collision) { transform.position = gravity; this.transform.Translate(forward); } } else if (b_landed) { UpdateGroundMovement(leftHydra, rightHydra); } } void UpdateGroundMovement(SixenseInput.Controller leftHydra, SixenseInput.Controller rightHydra) { Vector3 movement = new Vector3(leftHydra.JoystickX / 10, 0, leftHydra.JoystickY / 10); this.transform.Translate(movement); } float Map(float from, float to, float from2, float to2, float value) { if (value <= from2) { return(from); } else if (value >= to2) { return(to); } return((to - from) * ((value - from2) / (to2 - from2)) + from); } }
// Update is called once per frame void Update() { if (controller == null) { return; } transform.position = controller.Position * scale; if (controller.Trigger > 0.3f) { if (started) { ChunkManager.Instance.Draw(controller.Position * scale, radius * controller.Trigger, color); saved = false; } } else { // when clicking trigger to initialize controller, the first draw is always an error. started = true; } if (controller.GetButton(SixenseButtons.BUMPER)) { ChunkManager.Instance.Drag(controller.Position * scale, (controller.Position - lastPosition) * scale, controller.Rotation * Quaternion.Inverse(lastRotation)); } lastPosition = controller.Position; lastRotation = controller.Rotation; if (controller.GetButtonDown(SixenseButtons.START)) { ChunkManager.Instance.SaveChunks(scene + ".vox"); saved = true; } if (saved) { bool load = false; if (controller.GetButtonDown(SixenseButtons.ONE)) { load = true; scene = 1; } if (controller.GetButtonDown(SixenseButtons.TWO)) { load = true; scene = 2; } if (controller.GetButtonDown(SixenseButtons.THREE)) { load = true; scene = 3; } if (controller.GetButtonDown(SixenseButtons.FOUR)) { load = true; scene = 4; } if (load) { ChunkManager.Instance.LoadChunks(scene + ".vox"); } } var joystick = new Vector2(controller.JoystickX, controller.JoystickY); if (joystick.sqrMagnitude > 0.4f) { if (lastThumb.sqrMagnitude < 0.5f) { lastThumb = joystick.normalized; } if (Mathf.Abs(Vector3.Cross(joystick.normalized, lastThumb).z) > 0.5f) { int c = color + Mathf.RoundToInt(Mathf.Sign(Vector3.Cross(joystick.normalized, lastThumb).z)); lastThumb = joystick.normalized; if (c < 0) { c = (byte)(MarchingCubes.Builder.colorMap.Length - 1); } if (c >= MarchingCubes.Builder.colorMap.Length) { c = 0; } color = (byte)c; material.color = MarchingCubes.Builder.colorMap[color]; } } else { lastThumb = Vector2.zero; } }
void CalculateMovementSpeed(SixenseInput.Controller leftHydra, SixenseInput.Controller rightHydra) { if (rightHydra.GetButtonDown(SixenseButtons.BUMPER) || Input.GetButtonDown("SneakToggle")) { ToggleSneak(); } if (rightHydra.GetButton(SixenseButtons.TRIGGER) || leftHydra.GetButton(SixenseButtons.TRIGGER) || Input.GetButton("Jump")) { if (((rightHydra.GetButton(SixenseButtons.TRIGGER) && leftHydra.GetButton(SixenseButtons.TRIGGER)) || Input.GetButton("Sprint")) && f_sprintEnergy > 0.0f) { f_maxSpeed = 0.5f; f_sprintEnergy -= Time.deltaTime; f_speed += Time.deltaTime * 1.5f; if (b_sneaking) { ToggleSneak(); } //print ("SPRINT"); } else if (b_sneaking) { f_maxSpeed = 0.15f; f_sprintEnergy += Time.deltaTime; f_speed += Time.deltaTime; //print ("SNEAK"); } else if (rightHydra.Rotation.x < -0.4f && leftHydra.Rotation.x < -0.4f || Input.GetAxis("Vertical") < 0.0f) { f_minSpeed = -0.15f; f_speed -= Time.deltaTime; } else if (f_maxSpeed > 0.5f) { f_maxSpeed -= Time.deltaTime; } else { f_maxSpeed = 0.25f; f_sprintEnergy += Time.deltaTime / 2; f_speed += Time.deltaTime; //print ("WALK"); } } else { f_sprintEnergy += Time.deltaTime; f_speed -= Time.deltaTime * 2.0f; if (f_minSpeed < 0.0f) { f_minSpeed += Time.deltaTime; } else { f_minSpeed = 0.0f; } //print ("STAND"); } Mathf.Clamp(f_sprintEnergy, 0.0f, 10.0f); f_speed = Mathf.Clamp(f_speed, f_minSpeed, f_maxSpeed); }