protected void Update() { if (m_controller == null) { m_controller = SixenseInput.GetController(m_hand); } }
void Update() { if (!SixenseInput.IsBaseConnected(0)) { active = false; return; } for (var i = 0; i < SixenseInput.MAX_CONTROLLERS; i++) { if (SixenseInput.Controllers[i] == null || !SixenseInput.Controllers[i].Enabled) { continue; } active = true; int deviceIndex = k_DeviceOffset + (SixenseInput.Controllers[i].Hand == SixenseHands.LEFT ? 0 : 1); SendButtonEvents(i, deviceIndex); SendAxisEvents(i, deviceIndex); SendTrackingEvents(i, deviceIndex); } // Check for calibrate if (SixenseInput.Controllers[0] != null && SixenseInput.Controllers[1] != null) { if (SixenseInput.Controllers[0].GetButton(SixenseButtons.START) && SixenseInput.Controllers[1].GetButton(SixenseButtons.START)) { CalibrateControllers(); } } }
void Update() { razer = SixenseInput.GetController(controller); if (!GetComponent <Rigidbody>()) { // isRazerBaseMobile is false if Razer Hydra is not position, rotation, or compass source in headTracker if (headTracker && headTracker.isRazerBaseMobile) { movingBasePosition = headTracker.hydraBasePosition; movingBaseRotation = headTracker.hydraBaseRotation; } else { movingBasePosition = Vector3.zero; movingBaseRotation = Quaternion.identity; } transform.localPosition = movingBaseRotation * localPosition + movingBasePosition; transform.localRotation = movingBaseRotation * localRotation; } if (whereToCopyColor != null) { foreach (Material mat in whereToCopyColor.materials) { mat.color = color; } } }
protected override void UpdateObject(SixenseInput.Controller controller) { if (m_animator == null) return; GameObject CameraBase = GameObject.Find("CameraBase"); if ( CameraBase == null) return; HydraDeckCamera DeckCamera = CameraBase.GetComponentInChildren<HydraDeckCamera>(); if (DeckCamera == null) return; if (controller.Enabled) { // Animation update UpdateAnimationInput(controller); } if (!m_enabled && DeckCamera.State == HydraDeckCamera.CameraState.Enabled) { // enable position and orientation control m_enabled = !m_enabled; } if (m_enabled) { UpdatePosition(controller, DeckCamera); UpdateRotation(controller); } }
// Override GUI to only display instructions if Sixense hands exist and support display in OVR cameras. void OnGUI() { if (Hand == SixenseHands.UNKNOWN) { return; } if (SixenseInput.IsBaseConnected(0) && !m_enabled) { string handStr = Hand == SixenseHands.LEFT ? "left" : "right"; if (HMDPresent && StorageManager.data.optionControlsEnableRift == true) { string instructions = "To enable a Hydra controller:\n\r"; instructions += "Point it at base, pull trigger,\n\r"; instructions += "place on respective shoulder and press START\n\r"; DisplayStereoMessage(instructions, "center", "Sixense-center"); DisplayStereoMessage("Press " + handStr + " START\n\rto control " + gameObject.name, handStr, "Sixense-" + handStr); } else { int labelWidth = 250; int labelPadding = 120; int horizOffset = Hand == SixenseHands.LEFT ? -labelWidth - labelPadding : labelPadding; GUI.Box(new Rect(Screen.width / 2 + horizOffset, Screen.height - 40, labelWidth, 30), "Press " + handStr + " START to control " + gameObject.name); } } }
// Setup the scene for web player protected virtual void SetupWebPlayer() { if (!player) { return; } SixenseInput sixenseInput = player.GetComponentInChildren <SixenseInput> (); if (sixenseInput) { sixenseInput.enabled = false; } SixenseHandControllerExtender[] sixenseHandControllers = player.GetComponentsInChildren <SixenseHandControllerExtender> (); foreach (SixenseHandControllerExtender sixenseHandController in sixenseHandControllers) { sixenseHandController.enabled = false; } LeapHandControllerExtender leapHandController = player.GetComponentInChildren <LeapHandControllerExtender> (); if (leapHandController) { leapHandController.enabled = false; } }
// 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; } } }
// Updates the animated object from controller input. private void UpdateHand(SixenseInput.Controller controller) { if (Hand == SixenseHands.RIGHT && vrGrabHand != null) { vrGrabHand.thumbInput = 0f; if (controller.GetButton(SixenseButtons.ONE)) vrGrabHand.thumbInput = 0.5f; if (controller.GetButton(SixenseButtons.THREE)) vrGrabHand.thumbInput = 1f; vrGrabHand.indexInput = controller.GetButton(SixenseButtons.BUMPER) ? 1 : 0; vrGrabHand.middleInput = controller.Trigger; vrGrabHand.ringInput = controller.Trigger; vrGrabHand.littleInput = controller.Trigger; } if (Hand == SixenseHands.LEFT && vrGrabHand != null) { vrGrabHand.thumbInput = 0f; if (controller.GetButton(SixenseButtons.TWO)) vrGrabHand.thumbInput = 0.5f; if (controller.GetButton(SixenseButtons.FOUR)) vrGrabHand.thumbInput = 1f; vrGrabHand.indexInput = controller.GetButton(SixenseButtons.BUMPER) ? 1 : 0; vrGrabHand.middleInput = controller.Trigger; vrGrabHand.ringInput = controller.Trigger; vrGrabHand.littleInput = controller.Trigger; } }
protected override void UpdateObject( SixenseInput.Controller controller ) { if (controller.Enabled) UpdateHand(controller); if (!m_enabled && controller.Trigger > 0.01f) { m_enabled = true; // 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 && controller.GetButton(SixenseButtons.START)) { m_enabled = false; } if ( m_enabled ) { UpdatePosition( controller ); UpdateRotation( controller ); } }
// Update is called once per frame void Update() { if (SixenseInput.GetController(SixenseHands.LEFT).GetButtonDown(SixenseButtons.BUMPER)) { Destroy(this.gameObject); } }
protected void Update() { if (m_controller == null) { m_controller = SixenseInput.GetController(m_hand); } else { float xangle = m_controller.Rotation.eulerAngles.x; xangle = xangle > 90 && xangle < 180 ? 90 : xangle; xangle = xangle < 270 && xangle > 180 ? 270 : xangle; Quaternion rotation = Quaternion.identity; //transform.rotation = m_controller.Rotation; rotation.eulerAngles = new Vector3(xangle, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z); //rotation.eulerAngles = new Vector3(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z); transform.rotation = rotation; } /*else if ( m_animator != null ) * { * UpdateHandAnimation(); * }*/ // Debug.Log(m_controller.Rotation.eulerAngles.x); }
// Update is called once per frame void Update() { var controller = SixenseInput.GetController(SixenseHands.RIGHT); if (controller != null && controller.GetButtonDown(SixenseButtons.BUMPER)) { Instantiate(birdiePrefab, this.transform.position, Quaternion.identity); } }
// Update is called once per frame protected void Update() { if (m_controller == null) { m_controller = SixenseInput.GetController(m_hand); } else { } Debug.DrawLine(transform.position, Vector3.forward); }
// Updates the animated object from controller input. protected new void UpdateAnimationInput(SixenseInput.Controller controller) { /* // Point if (controller.GetButton(SixenseButtons.BUMPER)) { m_animator.SetBool("Point", true); } else { m_animator.SetBool("Point", false); } // HoldBook if (controller.GetButton(SixenseButtons.START)) { m_animator.SetBool("HoldBook", true); } else { m_animator.SetBool("HoldBook", false); } // Fist float fTriggerVal = controller.Trigger; fTriggerVal = Mathf.Lerp(m_fLastTriggerVal, fTriggerVal, 0.1f); m_fLastTriggerVal = fTriggerVal; if (fTriggerVal > 0.01f) { m_animator.SetBool("Fist", true); } else { m_animator.SetBool("Fist", false); } m_animator.SetFloat("FistAmount", fTriggerVal); // Idle if (m_animator.GetBool("Fist") == false && m_animator.GetBool("HoldBook") == false && m_animator.GetBool("GripBall") == false && m_animator.GetBool("Point") == false) { m_animator.SetBool("Idle", true); } else { m_animator.SetBool("Idle", false); } */ }
protected void UpdatePosition( SixenseInput.Controller controller ) { Vector3 controllerPosition = new Vector3( controller.Position.x * Sensitivity.x, controller.Position.y * Sensitivity.y, controller.Position.z * Sensitivity.z ); // distance controller has moved since enabling positional control Vector3 vDeltaControllerPos = controllerPosition - m_baseControllerPosition; // update the localposition of the object this.gameObject.transform.localPosition = m_initialPosition + vDeltaControllerPos; }
protected void Update() { if (m_controller == null) { m_controller = SixenseInput.GetController(m_hand); } else if (m_animator != null) { UpdateHandAnimation(); } }
void Update() { if (leftController == null || rightController == null) { leftController = SixenseInput.GetController(SixenseHands.LEFT); rightController = SixenseInput.GetController(SixenseHands.RIGHT); } if (rightController != null && rightController.Enabled) { //Rotate scene /*if (rightController.GetButtonDown (SixenseButtons.JOYSTICK)) { * * rotationX = player.transform.localEulerAngles.y + rightController.JoystickX * sensitivityX * Time.deltaTime; * * float joystickY = rightController.JoystickY; * * if (joystickY > 0.05f || joystickY < 0.0f) { * rotationY += rightController.JoystickY * sensitivitiY * Time.deltaTime; * rotationY = Mathf.Clamp (rotationY, minimumY, maximumY); * } * * player.transform.localEulerAngles = new Vector3 (0, rotationX, 0); * * Camera.current.transform.localEulerAngles = new Vector3 (-rotationY, 0, 0); * } */ //if(leftController.GetButtonDown (SixenseButtons.JOYSTICK)) { float x = rightController.JoystickX; float y = rightController.JoystickY; float R_analog_threshold = 0.10f; if (Mathf.Abs(x) < R_analog_threshold) { x = 0.0f; } if (Mathf.Abs(y) < R_analog_threshold) { y = 0.0f; } if (x != 0.0f || y != 0.0f) { rotAngle = Mathf.Atan2(y, x) * Mathf.Rad2Deg; transform.Rotate(new Vector3(0, x, y)); } //} } }
// Update is called once per frame void Update() { if (Hand == SixenseHands.UNKNOWN) { return; } SixenseInput.Controller controller = SixenseInput.GetController(Hand); if (controller != null && controller.Enabled) { UpdateObject(controller); } }
protected override void Update() { // Get the input vector from hydra SixenseInput.Controller hydraRightController = SixenseInput.GetController(SixenseHands.RIGHT); if (hydraRightController != null) { axisX = hydraRightController.JoystickX; axisY = hydraRightController.JoystickY; } base.Update(); }
// Update is called once per frame void Update() { if (m_controller == null) { m_controller = SixenseInput.GetController(m_hand); } else { ForwardSpeed(m_controller.JoystickY); LateralMovement(m_controller.JoystickX); } Debug.DrawLine(playerCam.transform.position, playerCam.transform.position + playerCam.transform.forward, Color.red); }
// Update is called once per frame void Update() { if (handL == null) { handL = GameObject.Find("Left Hand"); } if (handR == null) { handR = GameObject.Find("Right Hand"); } if (handL == null || handR == null) { return; } // Material mat = (Material) gameObject.GetComponent<Material>(); Vector3 l = handL.transform.position; Vector3 r = handR.transform.position; bool move = false; bool lCollide = gameObject.collider.bounds.Contains(l); bool rCollide = gameObject.collider.bounds.Contains(r); SixenseInput.Controller lControl = SixenseInput.GetController(SixenseHands.LEFT); SixenseInput.Controller rControl = SixenseInput.GetController(SixenseHands.RIGHT); if (lControl != null && rControl != null) { lDown = (lCollide || lDown) && lControl.GetButton(SixenseButtons.TRIGGER); rDown = (rCollide || rDown) && rControl.GetButton(SixenseButtons.TRIGGER); if (lDown && rDown) { move = true; //Vector3 v1 = gameObject.transform.rotation * (l - lPrev); //Vector3 v2 = gameObject.transform.rotation * (l - gameObject.transform.position); scaleSpeed = (r - l).magnitude - (rPrev - lPrev).magnitude; } lPrev = l; rPrev = r; } //gameObject.transform.Rotate(rotSpeed); totalScale += scaleSpeed; gameObject.transform.localScale = new Vector3(totalScale, totalScale, totalScale); scaleSpeed = scaleSpeed * .7f; //rotSpeed = new Vector3(0, 1, 0); }
protected override void UpdateObject( SixenseInput.Controller controller ) { if ( m_animator == null ) { return; } if ( controller.Enabled ) { // Animation update UpdateAnimationInput( controller ); } base.UpdateObject(controller); }
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; } }
// use FixedUpdate for rigidbody void FixedUpdate() { //var deltaY = Input.GetAxis ("Mouse Y"); //this.currentPosition.y += deltaY * this.ySensitivity; //var deltaX = Input.GetAxis ("Mouse X"); //this.currentPosition.x += deltaX * this.xSensitivity; var controller = SixenseInput.GetController(this.hand); if (controller != null && controller.Enabled) { // convert to meters this.currentPosition = controller.Position / 1000 + this.defaultPosition; this.currentRotation = controller.Rotation; this.SetPosition(this.currentPosition); this.SetRotatation(this.currentRotation); } }
private void GetInput(out float speed) { // Read input float horizontal = CrossPlatformInputManager.GetAxis("Horizontal"); float vertical = CrossPlatformInputManager.GetAxis("Vertical"); //Get the input vector from Hydra SixenseInput.Controller hydraLeftController = SixenseInput.GetController(SixenseHands.LEFT); SixenseInput.Controller hydraRightController = SixenseInput.GetController(SixenseHands.RIGHT); if (hydraLeftController != null && hydraLeftController.Enabled) { //Debug.Log ("Controle ok!"); horizontal = hydraLeftController.JoystickX; vertical = hydraLeftController.JoystickY; } bool waswalking = m_IsWalking; #if !MOBILE_INPUT // On standalone builds, walk/run speed is modified by a key press. // keep track of whether or not the character is walking or running m_IsWalking = !Input.GetKey(KeyCode.LeftShift); #endif // set the desired speed to be walking or running speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed; m_Input = new Vector2(horizontal, vertical); // normalize input if it exceeds 1 in combined length: if (m_Input.sqrMagnitude > 1) { m_Input.Normalize(); } // handle speed change to give an fov kick // only if the player is going to a run, is running and the fovkick is to be used if (m_IsWalking != waswalking && m_UseFovKick && m_CharacterController.velocity.sqrMagnitude > 0) { StopAllCoroutines(); StartCoroutine(!m_IsWalking ? m_FovKick.FOVKickUp() : m_FovKick.FOVKickDown()); } }
// Use this for initialization void Awake() { hydraInput = GameObject.FindGameObjectWithTag("HydraInput").GetComponent<SixenseInput>(); shipMove = gameObject.GetComponent<ShipMove>(); shipAttack = gameObject.GetComponent<ShipAttack>(); playerInventory = gameObject.GetComponent<PlayerInventory>(); switch (GOD.whatControllerAmIUsing) { case WhatControllerAmIUsing.KEYBOARD: hydraInput.enabled = false; break; case WhatControllerAmIUsing.MOUSE_KEYBOARD: hydraInput.enabled = false; break; case WhatControllerAmIUsing.HYDRA: hydraInput.enabled = true; break; default: break; } }
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 ); } }
protected override void UpdateInput(ref float horizontal, ref float vertical) { if (_controller == null) { _controller = SixenseInput.GetController(_hand); } if (_controller != null) { horizontal = _controller.JoystickX * _sensibilityX; vertical = _controller.JoystickY * _sensibilityY; } if (Mathf.Abs(horizontal) < _deadZone) { horizontal = 0.0f; } if (Mathf.Abs(vertical) < _deadZone) { vertical = 0.0f; } }
/* * Updaters */ void Update() { if (m_leftHandController == null) { m_leftHandController = SixenseInput.GetController(SixenseHands.LEFT); } if (m_rightHandController == null) { m_rightHandController = SixenseInput.GetController(SixenseHands.RIGHT); } //Hand velocities m_leftHandVelocity = m_leftHand.transform.position - m_lastLeftHandPos; m_rightHandVelocity = m_rightHand.transform.position - m_lastRightHandPos; m_lastLeftHandPos = m_leftHand.transform.position; m_lastRightHandPos = m_rightHand.transform.position; SetCommonTools(BaseTool.ToolHand.LEFT); SetCommonTools(BaseTool.ToolHand.RIGHT); SetIndividualToolsRight(BaseTool.ToolHand.LEFT); //SetRhythmTools(m_rhythmGlove); }
protected void Update() { if (m_controller == null) { m_controller = SixenseInput.GetController(m_hand); } else if ((HydraScript.gameState & 1) == 1) { Vector3 directionVector = new Vector3(m_controller.JoystickX, 0, m_controller.JoystickY); directionVector += new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); directionVector.Normalize(); motor.inputMoveDirection = transform.rotation * directionVector; /* * * float deltaY = m_controller.Rotation.eulerAngles.y - previousY; * deltaY *= 3; * * float yangle = transform.rotation.eulerAngles.y + deltaY; * //yangle = yangle > 90 && yangle < 180 ? 90 : yangle; * //yangle = yangle < 270 && yangle > 180 ? 270 : yangle; * Quaternion rotation = Quaternion.identity; * //transform.rotation = m_controller.Rotation; * rotation.eulerAngles = new Vector3(transform.rotation.eulerAngles.x, yangle, transform.rotation.eulerAngles.z); * //rotation.eulerAngles = new Vector3(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z); * transform.rotation = rotation; */ } /*else if ( m_animator != null ) * { * UpdateHandAnimation(); * }*/ // Debug.Log(m_controller.Rotation.eulerAngles.x); }
protected void Update() { if (m_controller == null) { m_controller = SixenseInput.GetController(m_hand); Debug.Log(m_controller); } else { motor.inputJump = m_controller.GetButton(SixenseButtons.BUMPER); if (m_controller.GetButton(SixenseButtons.ONE) && (HydraScript.gameState & 1) == 1) { float deltaY = m_controller.Rotation.eulerAngles.y - previousY; deltaY *= 3; float yangle = transform.rotation.eulerAngles.y + deltaY; //yangle = yangle > 90 && yangle < 180 ? 90 : yangle; //yangle = yangle < 270 && yangle > 180 ? 270 : yangle; Quaternion rotation = Quaternion.identity; //transform.rotation = m_controller.Rotation; rotation.eulerAngles = new Vector3(transform.rotation.eulerAngles.x, yangle, transform.rotation.eulerAngles.z); //rotation.eulerAngles = new Vector3(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z); transform.rotation = rotation; } previousY = m_controller.Rotation.eulerAngles.y; } /*else if ( m_animator != null ) * { * UpdateHandAnimation(); * }*/ // Debug.Log(m_controller.Rotation.eulerAngles.x); }
// Use this for initialization IEnumerator Start() { if (hand == SixenseHands.RIGHT) { ChunkManager.Instance.LoadChunks(scene + ".vox"); } while (SixenseInput.GetController(hand) == null) { yield return(null); } var renderers = GetComponentsInChildren <Renderer>(true); for (int i = 0; i < renderers.Length; i++) { renderers[i].enabled = true; } material = GetComponentInChildren <Renderer>().sharedMaterial; material.color = MarchingCubes.Builder.colorMap[color]; controller = SixenseInput.GetController(hand); }
void FixedUpdate() { //characterController.ApplyForceInCharacterDirection(translation); direction = 0; turnMagnitude = 0; if (characterController != null) { grounded = characterController.grounded; colliding = characterController.colliding; } if (grounded || colliding) { airborne = false; } else { if (!airborne) { jumpTimeVelocity = rigidbody.velocity; jumpTimeVelocity.y = 0; jumpTimeVelocity = Vector3.ClampMagnitude(jumpTimeVelocity, aerialMobility * speed); airborneAccumulatedVelocity = jumpTimeVelocity; } airborne = true; } targetVelocity = Vector2.zero; extraSpeed = 0; try { targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); } catch (UnityException) { } try { extraSpeed = Input.GetAxis("Sprint"); if (!airborne) { targetVelocity *= 1 + extraSpeed * runAdder; } } catch (UnityException) { } // Check if moving with PS Move Navigation controller if (PSNaviControllerID < 1) { Debug.LogError("PSNaviControllerID was set to " + PSNaviControllerID + " which is incorrect value: It must be positive!"); } else if (usePSNavigationController && moveWrapper && moveWrapper.isConnected) { if (PSNaviControllerID <= moveWrapper.navConnected.Length) { if (moveWrapper.navConnected[PSNaviControllerID - 1]) { int horiz = moveWrapper.valueNavAnalogX[PSNaviControllerID - 1]; int verti = moveWrapper.valueNavAnalogY[PSNaviControllerID - 1]; if (!airborne) { extraSpeed = ((float)moveWrapper.valueNavL2[PSNaviControllerID - 1]) / 255f; } else { extraSpeed = 0; } if (Mathf.Abs(verti) > 20) { targetVelocity += new Vector3(0, 0, -((float)verti) / 128f * (1 + extraSpeed * runAdder)); } if (strafeInsteadTurning) { if (Mathf.Abs(horiz) > 20) { targetVelocity += new Vector3(((float)horiz) / 128f * (1 + extraSpeed * runAdder), 0, 0); } } else { if (Mathf.Abs(horiz) > 10) { turnMagnitude += ((float)horiz) / 128f; } } if (moveWrapper.isNavButtonCross[PSNaviControllerID - 1]) { turnMagnitude -= 1; } if (moveWrapper.isNavButtonCircle[PSNaviControllerID - 1]) { turnMagnitude += 1; } } } else { Debug.LogError("PSNaviControllerID was set to " + PSNaviControllerID + " which is too big value: It must be below 8."); } } // TUUKKA if (useRazerHydra) // Check if moving with Razer Hydra controller { razerController = SixenseInput.GetController(razerHydraID); if (razerController != null && razerController.Enabled) { if (!airborne) { if (razerController.GetButton(SixenseButtons.JOYSTICK)) { extraSpeed = 1; //razerController.Trigger; } else { extraSpeed = 0; } } if (Mathf.Abs(razerController.JoystickY) > 0.15f) { targetVelocity += new Vector3(0, 0, razerController.JoystickY * (1 + extraSpeed * runAdder)); } if (strafeInsteadTurning) { if (Mathf.Abs(razerController.JoystickX) > 0.15f) { targetVelocity += new Vector3(razerController.JoystickX * (1 + extraSpeed * runAdder), 0, 0); } } else { if (Mathf.Abs(razerController.JoystickX) > 0.075f) { turnMagnitude += razerController.JoystickX; } } if (razerController.GetButton(SixenseButtons.THREE)) { turnMagnitude -= 1; } if (razerController.GetButton(SixenseButtons.FOUR)) { turnMagnitude += 1; } } } // controlDirection is a unit vector that shows the direction where the joystick is pressed controlDirection = Vector3.ClampMagnitude(targetVelocity, 1); // desiredVelocity is a vector with magnitude between 0 (not moving) and 2 (sprinting) desiredVelocity = Vector3.ClampMagnitude(targetVelocity, 1 + extraSpeed); // Limit comes from [0,1] + extraSpeed*runAdder targetVelocity = Vector3.ClampMagnitude(targetVelocity, 1 + extraSpeed * runAdder); targetVelocity = characterController.TransformDirection(targetVelocity); targetVelocity *= speed; velocity = rigidbody.velocity; velocityChange = (targetVelocity - velocity); velocityChange.y = 0; velocityChange = Vector3.ClampMagnitude(velocityChange, Time.fixedDeltaTime * maxVelocityChange); if (!airborne) { rigidbody.AddForce(velocityChange, ForceMode.VelocityChange); } else { // Calculate constant air drag whose direction is opposite to the current horizontal velocity vector tempVelocity = velocity; tempVelocity.y = 0; tempAcceleration = -aerialDrag * tempVelocity.normalized; tempAcceleration.y = 0; // The drag should only stop the character, not push him like a wind in the opposite direction // This condition is true when the tempVelocity is close to zero and its normalization fails if (Vector3.Dot(tempVelocity, tempAcceleration) >= 0) { tempAcceleration = Vector3.zero; } // Calculate proposed acceleration as a sum of player controls and air drag proposedAcceleration = aerialAcceleration * characterController.TransformDirection(desiredVelocity) + tempAcceleration; // Integrate proposed total velocity = old velocity + proposed acceleration * deltaT proposedVelocity = airborneAccumulatedVelocity + (proposedAcceleration) * Time.fixedDeltaTime; // If the proposed total velocity is not inside "aerial velocity disc", then shorten the proposed velocity // with length of [proposed acceleration * deltaT]. This allows aerial maneuvers along the edge of the disc (circle). // In other words: If you have reach maximum aerial velocity to certain direction, you can still control the // velocity in the axis that is perpendicular to that direction if (proposedVelocity.magnitude >= aerialMobility * speed) { proposedVelocity -= 1.01f * airborneAccumulatedVelocity.normalized * proposedAcceleration.magnitude * Time.fixedDeltaTime; proposedAcceleration -= 1.01f * airborneAccumulatedVelocity.normalized * proposedAcceleration.magnitude; } // If the proposed total velocity is within allowed "aerial velocity disc", then add the proposed // acceleration to the character and update the accumulatedAerialSpeed accordingly if (proposedVelocity.magnitude < aerialMobility * speed) { rigidbody.AddForce(proposedAcceleration, ForceMode.Acceleration); airborneAccumulatedVelocity = proposedVelocity; } } try { turnMagnitude += Input.GetAxis("Turn"); } catch (UnityException) { } if (Input.GetKey(turnLeftKey)) { turnMagnitude -= 1; } if (Input.GetKey(turnRightKey)) { turnMagnitude += 1; } if (turnMagnitude != 0) { characterController.RotateAroundCharacterPivot(new Vector3(0, turnMagnitude * rotationScaler * Time.fixedDeltaTime, 0)); } if (shouldJump) { rigidbody.AddForce(new Vector3(0, Mathf.Sqrt((1 + 0.5f * (controlDirection.magnitude + extraSpeed) * jumpSpeedEffect) * jumpStrength) * rigidbody.mass, 0), ForceMode.Impulse); if (characterController) { characterController.lastJumpTime = Time.fixedTime; } shouldJump = false; } }
protected override void UpdateObject(SixenseInput.Controller controller) { if (m_animator == null) return; GameObject CameraBase = GameObject.Find("OVRCameraController"); if ( CameraBase == null) return; HydraDeckCamera DeckCamera = CameraBase.GetComponentInChildren<HydraDeckCamera>(); if (DeckCamera == null) return; if (controller.Enabled) { // Animation update UpdateAnimationInput(controller); } if (!m_enabled && DeckCamera.State == HydraDeckCamera.CameraState.Enabled) { // enable position and orientation control m_enabled = !m_enabled; } if (m_enabled) { if (controller.GetButtonDown(SixenseButtons.TRIGGER)){ LookAtCue = true; } if (controller.GetButtonUp(SixenseButtons.TRIGGER)){ LookAtCue = false; } if (controller.GetButtonDown(SixenseButtons.BUMPER)){ Application.LoadLevel(0); } UpdatePosition(controller, DeckCamera); UpdateRotation(controller); } }
// Updates the animated object from controller input. protected void UpdateAnimationInput( SixenseInput.Controller controller) { // Point if ( Hand == SixenseHands.RIGHT ? controller.GetButton(SixenseButtons.ONE) : controller.GetButton(SixenseButtons.TWO) ) { m_animator.SetBool( "Point", true ); } else { m_animator.SetBool( "Point", false ); } // Grip Ball if ( Hand == SixenseHands.RIGHT ? controller.GetButton(SixenseButtons.TWO) : controller.GetButton(SixenseButtons.ONE) ) { m_animator.SetBool( "GripBall", true ); } else { m_animator.SetBool( "GripBall", false ); } // Hold Book if ( Hand == SixenseHands.RIGHT ? controller.GetButton(SixenseButtons.THREE) : controller.GetButton(SixenseButtons.FOUR) ) { m_animator.SetBool( "HoldBook", true ); } else { m_animator.SetBool( "HoldBook", false ); } // Fist float fTriggerVal = controller.Trigger; fTriggerVal = Mathf.Lerp( m_fLastTriggerVal, fTriggerVal, 0.1f ); m_fLastTriggerVal = fTriggerVal; if ( fTriggerVal > 0.01f ) { m_animator.SetBool( "Fist", true ); } else { m_animator.SetBool( "Fist", false ); } m_animator.SetFloat("FistAmount", fTriggerVal); // Idle if ( m_animator.GetBool("Fist") == false && m_animator.GetBool("HoldBook") == false && m_animator.GetBool("GripBall") == false && m_animator.GetBool("Point") == false ) { m_animator.SetBool("Idle", true); } else { m_animator.SetBool("Idle", false); } }
// 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"; } } } }
protected void UpdatePosition(SixenseInput.Controller controller, HydraDeckCamera DeckCamera) { if (InitialYCuePosition == 0.0f){ InitialYCuePosition = this.gameObject.transform.position.y - 0.2f; } Vector3 BodyPosition = DeckCamera.BodyPosition; Vector3 controllerPosition = new Vector3(controller.Position.x, InitialYCuePosition, controller.Position.z); //Orientate it to our scene controllerPosition = DeckCamera.StartCameraOffset * controllerPosition; controllerPosition.Scale(DeckCamera.HydraToWorldScale); if (InitialZControllerPosition == 0.0f){ InitialZControllerPosition = controllerPosition.z; } float distance = ((float)(controllerPosition.z - InitialZControllerPosition) * 1.5f); // update the localposition of the object this.gameObject.transform.position = BodyPosition + controllerPosition; this.gameObject.transform.position = new Vector3(gameObject.transform.position.x, InitialYCuePosition, gameObject.transform.position.z); this.gameObject.transform.localPosition = new Vector3(gameObject.transform.localPosition.x, gameObject.transform.localPosition.y, gameObject.transform.position.z + distance); }
protected void UpdateRotation( SixenseInput.Controller controller ) { Quaternion controllerRotation = new Quaternion( -controller.Rotation.z, controller.Rotation.y, controller.Rotation.x, controller.Rotation.w); this.gameObject.transform.localRotation = controllerRotation * m_initialRotation; //controller.Rotation.z }
/// <summary> SAM WAS HERE SINGLETONING IT UP</summary> void Awake() { if (instance) { Debug.Log("SixsenseInput already exists, destroying this one!"); GameObject.Destroy(this.gameObject); return; } GameObject.DontDestroyOnLoad(this.gameObject); instance = this; }
// Updates the animated object from controller input. protected void UpdateAnimationInput( SixenseInput.Controller controller) { // Tools can only be used by the right hand if (Hand == SixenseHands.RIGHT) { if ( Hand == SixenseHands.RIGHT ? controller.GetButton(SixenseButtons.ONE) : controller.GetButton(SixenseButtons.TWO) ) { if(!m_toolPressed) { NextTool(); Debug.Log ("What"); } m_toolPressed = true; m_animator.SetBool( "Point", true ); } else { m_toolPressed = false; m_animator.SetBool( "Point", false ); } } else { // Grip Ball if ( Hand == SixenseHands.RIGHT ? controller.GetButton(SixenseButtons.TWO) : controller.GetButton(SixenseButtons.ONE) ) { m_animator.SetBool( "GripBall", true ); } else { m_animator.SetBool( "GripBall", false ); } // Hold Book if ( Hand == SixenseHands.RIGHT ? controller.GetButton(SixenseButtons.THREE) : controller.GetButton(SixenseButtons.FOUR) ) { m_animator.SetBool( "HoldBook", true ); } else { m_animator.SetBool( "HoldBook", false ); } } // Fist float fTriggerVal = controller.Trigger; if (fTriggerVal > 0.01f) { if (Hand == SixenseHands.RIGHT) { if(m_tool && !m_isActivating) { m_tool.Activate(); m_isActivating = true; } } else { m_pickupZone.Grab(); } } else { if (Hand == SixenseHands.RIGHT) { m_isActivating = false; } else { m_pickupZone.Drop(); } } fTriggerVal = Mathf.Lerp( m_fLastTriggerVal, fTriggerVal, 0.1f ); m_fLastTriggerVal = fTriggerVal; if ( fTriggerVal > 0.01f ) { m_animator.SetBool( "Fist", true ); } else { m_animator.SetBool( "Fist", false ); } m_animator.SetFloat("FistAmount", fTriggerVal); // Idle if ( m_animator.GetBool("Fist") == false && m_animator.GetBool("HoldBook") == false && m_animator.GetBool("GripBall") == false && m_animator.GetBool("Point") == false ) { m_animator.SetBool("Idle", true); } else { m_animator.SetBool("Idle", false); } }
public void Awake() { // Check if we are in calibration scene ruisNGUIMenu = FindObjectOfType(typeof(RUISMenuNGUI)) as RUISMenuNGUI; if(ruisNGUIMenu != null) { if(ruisNGUIMenu.currentMenuState == RUISMenuNGUI.RUISMenuStates.calibration) { this.enablePSMove = ruisNGUIMenu.originalEnablePSMove; this.enableKinect = ruisNGUIMenu.originalEnableKinect; this.enableKinect2 = ruisNGUIMenu.originalEnableKinect2; this.jumpGestureEnabled = ruisNGUIMenu.originalEnableJumpGesture; this.enableRazerHydra = ruisNGUIMenu.originalEnableHydra; this.kinectDriftCorrectionPreferred = ruisNGUIMenu.originalKinectDriftCorrection; this.PSMoveIP = ruisNGUIMenu.originalPSMoveIP; this.PSMovePort = ruisNGUIMenu.originalPSMovePort; } } wandDelayed = new bool[4] {moveWand0, moveWand1, moveWand2, moveWand3}; disabledWands = new List<GameObject>(); if (!Application.isEditor || loadFromTextFileInEditor) { if (!Import(filename)) { Debug.LogError("Could not load input configuration file. Creating file based on current settings."); Export(filename); } } if (!enableKinect) { Debug.Log("Kinect is disabled from RUISInputManager."); GetComponentInChildren<RUISKinectDisabler>().KinectNotAvailable(); } else { GetComponentInChildren<NIPlayerManagerCOMSelection>().m_MaxNumberOfPlayers = maxNumberOfKinectPlayers; } psMoveWrapper = GetComponentInChildren<PSMoveWrapper>(); if (enablePSMove) { if (psMoveWrapper && connectToPSMoveOnStartup) { StartCoroutine("CheckForMoveConnection"); psMoveWrapper.Connect(PSMoveIP, PSMovePort); psMoveWrapper.enableDefaultInGameCalibrate = enableMoveCalibrationDuringPlay; if(delayedWandActivation) { string names = ""; foreach (RUISPSMoveWand moveController in FindObjectsOfType(typeof(RUISPSMoveWand)) as RUISPSMoveWand[]) { if( moveController != null && moveController.controllerId < 4 && moveController.controllerId >= 0 && wandDelayed[moveController.controllerId] ) { // Make sure that the found RUISPSMoveWand is not under InputManager->MoveControllers GameObject if( moveController.gameObject.transform.parent == null || moveController.gameObject.transform.parent.parent == null || ( moveController.gameObject.transform.parent.GetComponent<RUISInputManager>() == null && moveController.gameObject.transform.parent.parent.GetComponent<RUISInputManager>() == null)) { moveController.gameObject.SetActive(false); disabledWands.Add(moveController.gameObject); if(names.Length > 0) names += ", "; names += moveController.gameObject.name; } } } if(disabledWands.Count > 0) { Debug.Log( "DELAYED CONTROLLER ACTIVATION INITIALIZATION: Following objects are disabled: " + names + ". If their input devices are found, they will be re-activated in " + delayTime + " seconds, as configured in RUISInputManager."); StartCoroutine("DelayedWandActivation"); } } } } else { Debug.Log("PS Move is disabled from RUISInputManager."); //psMoveWrapper.gameObject.SetActiveRecursively(false); } sixense = FindObjectOfType(typeof(SixenseInput)) as SixenseInput; if(enableRazerHydra) { if(sixense == null) Debug.LogError( "Could not connect with Razer Hydra! Your RUIS InputManager settings indicate " + "that you want to use Razer Hydra, but this scene does not have a gameobject " + "with SixenseInput script, which is required. Add SixenseInput prefab " + "into the scene."); // IsBaseConnected() seems to crash Unity at least when called here // else if(!SixenseInput.IsBaseConnected(0)) // TODO: *** Apparently there can be multiple bases // Debug.LogError( "Could not connect with Razer Hydra! Check the USB connection."); } else { if(sixense != null) { sixense.gameObject.SetActive(false); Debug.Log( "Razer Hydra is disabled from RUISInputManager. Disabling object " + sixense.name + " that has the SixenseInput script."); } } DisableUnneededMoveWands(); DisableUnneededRazerHydraWands(); }
/// <summary> /// Updates the position of the razer controller on the scene. /// </summary> /// <param name="controller">razer hydra.</param> void UpdatePosition(SixenseInput.Controller controller) { Vector3 controllerPosition = new Vector3(controller.Position.x * _sensitivity.x, controller.Position.y * _sensitivity.y, controller.Position.z * _sensitivity.z); if (controller.GetButtonDown (SixenseButtons.TRIGGER)) { GetInitialPositionAvatar(); _tmpPosition = m_initialPosition - controllerPosition; } this.gameObject.transform.localPosition = _tmpPosition + controllerPosition; }
protected void Update()//override SixenseObjectController Update { _controller = SixenseInput.GetController(Hand); if (_controller != null && _controller.Enabled) UpdateHandAnimation(); }
// 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> (); } } } }
/*void OnGUI() { if ( !m_enabled ) { GUI.Box( new Rect( Screen.width / 2 - 100, Screen.height - 40, 200, 30 ), "Press Start To Move/Rotate" ); } }*/ protected virtual void UpdateObject( SixenseInput.Controller controller ) { if ( Input.GetKeyDown (KeyCode.E) || Input.GetKeyDown (KeyCode.F) || Input.GetKeyDown (KeyCode.T)/*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.z * Sensitivity.x, controller.Position.y * Sensitivity.y, controller.Position.x * Sensitivity.z ); // this is the new start position m_initialPosition = this.gameObject.transform.localPosition; gameObject.GetComponentInChildren<MeshRenderer>().enabled = m_enabled; } /*if (m_enabled && controller.GetButtonDown (SixenseButtons.JOYSTICK)) { this.gameObject.transform.Translate(0.0f,controller.JoystickY,controller.JoystickX); }*/ if ( m_enabled ) { //Déplacement du gameObject au joystick m_initialPosition += new Vector3(0.0f,controller.JoystickY*0.01f,controller.JoystickX*0.01f); Debug.Log(new Vector3(0.0f,controller.JoystickY,controller.JoystickX)); //Déplacement en profondeur du gameObject via RB RT if(controller.GetButton( SixenseButtons.BUMPER )){ m_initialPosition += new Vector3(0.005f,0.0f,0.0f); }else if (controller.GetButton( SixenseButtons.TRIGGER )){ m_initialPosition -= new Vector3(0.005f,0.0f,0.0f); } // Rotation suivant l'axe Y via les boutons 1 & 3 if(controller.GetButton( SixenseButtons.ONE )){ m_initialRotation.y += 0.005f; }else if (controller.GetButton( SixenseButtons.THREE )){ m_initialRotation.y -= 0.005f; } // Rotation suivant l'axe Z via les boutons 2 & 4 /*if(controller.GetButton( SixenseButtons.TWO )){ m_initialRotation.z += 0.005f; }else if (controller.GetButton( SixenseButtons.FOUR )){ m_initialRotation.z -= 0.005f; }*/ // Modifie la sensibilité via les boutons 2 & 4 if(controller.GetButton( SixenseButtons.TWO )){ Sensitivity += new Vector3(0.00001f,0.00001f,0.00001f); /*m_baseControllerPosition = new Vector3( -controller.Position.z * Sensitivity.x, controller.Position.y * Sensitivity.y, controller.Position.x * Sensitivity.z );*/ }else if (controller.GetButton( SixenseButtons.FOUR )){ if(Sensitivity.x > 0.0f){ Sensitivity -= new Vector3(0.00001f,0.00001f,0.00001f); /*m_baseControllerPosition = new Vector3( -controller.Position.z * Sensitivity.x, controller.Position.y * Sensitivity.y, controller.Position.x * Sensitivity.z );*/ } } UpdatePosition( controller ); if (ActivateRotations){ UpdateRotation( controller ); } } }
void MoveWheel(SixenseInput.Controller currentHydra, bool isRightHydra, GameObject currentHand, bool handIsRight) { //print ("MoveWheel "+isRightHydra); float rightLeftDifference; float upDownDifference; bool aboveMid; if(isRightHydra) { // negative is right, positive is left rightLeftDifference = previousHandPositionRight.x - currentHydra.Position.x; // negative is up, positive is down upDownDifference = previousHandPositionRight.y - currentHydra.Position.y; aboveMid = currentHand.transform.position.y > this.transform.position.y; } else { // negative is right, positive is left rightLeftDifference = previousHandPositionLeft.x - currentHydra.Position.x; // negative is up, positive is down upDownDifference = previousHandPositionLeft.y - currentHydra.Position.y; aboveMid = currentHand.transform.position.y > this.transform.position.y; } //print (currentHydra.Position.x); //print ("rightLeftDifference: "+rightLeftDifference); //print ("upDownDifference: "+upDownDifference); //isRotation = IsRotation.Not; // bool rechts = hand.transform.position.x > this.transform.position.x; float handDifference = Mathf.Max(Mathf.Abs(rightLeftDifference), Mathf.Abs(upDownDifference)); wheelRotationSpeed = handDifference * wheelRotationMultiplier; if(handDifference > 1.0f) { if(Mathf.Abs(rightLeftDifference) > Mathf.Abs(upDownDifference)) { //print ("rechtslinks"); if((rightLeftDifference < 0.0f && aboveMid) || (rightLeftDifference > 0.0f && !aboveMid)) { //print ("oben/rechts oder unten/links"); rotateWheel(wheelRotationSpeed); } else if((rightLeftDifference > 0.0f && aboveMid) || (rightLeftDifference < 0.0f && !aboveMid)) { //print ("oben/links oder unten/rechts"); rotateWheel(-wheelRotationSpeed); } } else if(Mathf.Abs(rightLeftDifference) < Mathf.Abs(upDownDifference)) { //print ("hochrunter"); //print ("rechts: "+isRightHandRight.Equals(currentHand)); if((upDownDifference < 0.0f && handIsRight) || (upDownDifference > 0.0f && !handIsRight)) { //print ("rechts/hoch oder links/runter"); rotateWheel(-wheelRotationSpeed); } else if((upDownDifference > 0.0f && handIsRight) || (upDownDifference < 0.0f && !handIsRight)) { //print ("rechts/runter oder links/hoch"); rotateWheel(wheelRotationSpeed); } } } }
float m_sensitivity = 0.001f; // Sixense units are in mm #endregion Fields #region Methods /** returns true if a controller is enabled and not docked */ bool IsControllerActive( SixenseInput.Controller controller ) { return ( controller != null && controller.Enabled && !controller.Docked ); }
/** returns true if a controller is enabled and not docked */ bool IsControllerActive( SixenseInput.Controller controller ) { return ( controller != null && (controller.Enabled || m_bInitialized) && !controller.Docked ); }
void UpdateHydraCamera(SixenseInput.Controller LeftController, SixenseInput.Controller RightController) { #region Movement float movementMultiplier = movementSpeed * Time.deltaTime * (RightController.GetButtonDown(SixenseButtons.TRIGGER) ? sprintMultiplier : 1.0f); Quaternion FullBodyRotation = StartCameraOffset * LeftController.Rotation * LeftRotationOffset; //lol, why doesn't Unity have a Quaternion.Normalize function? Quaternion rotationToFaceForward = FullBodyRotation; rotationToFaceForward.x = 0; rotationToFaceForward.z = 0; rotationToFaceForward = Quaternion.Lerp(rotationToFaceForward, rotationToFaceForward, 1); float forwardBackwardTranslation = RightController.JoystickY * movementMultiplier; float leftRightTranslation = RightController.JoystickX * movementMultiplier; Vector3 movementVector = new Vector3(leftRightTranslation, 0, forwardBackwardTranslation); if( movementVector != Vector3.zero ) { movementVector = rotationToFaceForward * movementVector; movementVector.y = 0; targetPosition += movementVector; } Vector3 currentPosition = BodyPosition; if( !Approximately(currentPosition, targetPosition) ) { currentPosition = Vector3.SmoothDamp(currentPosition, targetPosition, ref currentVelocity, movementSmoothingFactor, float.PositiveInfinity, Time.deltaTime); BodyPosition = currentPosition; } //Get the position of the left controller, and subtract the floor height Vector3 HydraLocation = new Vector3(LeftController.Position.x, LeftController.Position.y - HydraFloorY, LeftController.Position.z); //Orientate it to our scene HydraLocation = StartCameraOffset * HydraLocation; //Add the rotated offset from left hyrda to neck Vector3 ChestToNeckLocal = FullBodyRotation * ChestToNeckOffset; HydraLocation += ChestToNeckLocal; //Apply the scaling from Hydra units to World units HydraLocation.Scale(HydraToWorldScale); //Add in the eye offset, rotated by the body's yaw OVRCameraController CameraController = GetComponentInChildren<OVRCameraController>(); Vector3 NeckToEyes = new Vector3( CameraController.EyeCenterPosition.x, CameraController.EyeCenterPosition.y, CameraController.EyeCenterPosition.z ); NeckToEyes.y = 0; // not sure why, but changing height gives me wrong results? Vector3 NeckToEyesLocal = rotationToFaceForward * NeckToEyes; transform.position = BodyPosition + HydraLocation + NeckToEyesLocal; #endregion }
protected void UpdatePosition(SixenseInput.Controller controller, HydraDeckCamera DeckCamera) { Vector3 BodyPosition = DeckCamera.BodyPosition; Vector3 controllerPosition = new Vector3(controller.Position.x, controller.Position.y - DeckCamera.HydraFloorY, controller.Position.z); //Orientate it to our scene controllerPosition = DeckCamera.StartCameraOffset * controllerPosition; controllerPosition.Scale(DeckCamera.HydraToWorldScale); // update the localposition of the object this.gameObject.transform.position = BodyPosition + controllerPosition; }
protected void UpdateRotation( SixenseInput.Controller controller ) { this.gameObject.transform.localRotation = controller.Rotation * m_initialRotation; }
void Update() { GameObject guiText = null; guiText = GameObject.Find("gui_text_base_connected"); if (guiText) { guiText.GetComponent <GUIText>().text = "Base Connected = " + SixenseInput.IsBaseConnected(0); } for (uint i = 0; i < 2; i++) { if (SixenseInput.Controllers[i] != null) { uint controllerNumber = i + 1; guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_enabled"); if (guiText) { guiText.GetComponent <GUIText>().text = "Enabled = " + SixenseInput.Controllers[i].Enabled; } guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_docked"); if (guiText) { guiText.GetComponent <GUIText>().text = "Docked = "; if (SixenseInput.Controllers[i].Enabled) { guiText.GetComponent <GUIText>().text += SixenseInput.Controllers[i].Docked; } } guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_hand"); if (guiText) { guiText.GetComponent <GUIText>().text = "Hand = "; if (SixenseInput.Controllers[i].Enabled) { guiText.GetComponent <GUIText>().text += SixenseInput.Controllers[i].Hand; } } guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_buttons"); GameObject guiText2 = GameObject.Find("gui_text_controller_" + controllerNumber + "_buttons_2");; if (guiText && guiText2) { uint buttonsCount = 0; string buttonsText = ""; string buttonsText2 = ""; if (SixenseInput.Controllers[i].Enabled) { foreach (SixenseButtons button in System.Enum.GetValues(typeof(SixenseButtons))) { if (SixenseInput.Controllers[i].GetButton(button) && (buttonsCount < 4)) { if (buttonsText != "") { buttonsText += " | "; } buttonsText += button; buttonsCount++; } else if (SixenseInput.Controllers[i].GetButton(button) && (buttonsCount >= 4)) { if (buttonsText2 != "") { buttonsText2 += " | "; } buttonsText2 += button; buttonsCount++; } //if ( SixenseInput.Controllers[i].GetButtonDown( button ) ) //{ // Debug.Log( "Pressed = " + button ); //} //if ( SixenseInput.Controllers[i].GetButtonUp( button ) ) //{ // Debug.Log( "Released = " + button ); //} } } guiText.GetComponent <GUIText>().text = "Buttons = " + buttonsText; guiText2.GetComponent <GUIText>().text = "" + buttonsText2; } guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_trigger"); if (guiText) { guiText.GetComponent <GUIText>().text = "Trigger = "; if (SixenseInput.Controllers[i].Enabled) { guiText.GetComponent <GUIText>().text += SixenseInput.Controllers[i].Trigger; } } guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_joystick_x"); if (guiText) { guiText.GetComponent <GUIText>().text = "Joystick X = "; if (SixenseInput.Controllers[i].Enabled) { guiText.GetComponent <GUIText>().text += SixenseInput.Controllers[i].JoystickX; } } guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_joystick_y"); if (guiText) { guiText.GetComponent <GUIText>().text = "Joystick Y = "; if (SixenseInput.Controllers[i].Enabled) { guiText.GetComponent <GUIText>().text += SixenseInput.Controllers[i].JoystickY; } } guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_position"); if (guiText) { guiText.GetComponent <GUIText>().text = "Position = "; if (SixenseInput.Controllers[i].Enabled) { guiText.GetComponent <GUIText>().text += SixenseInput.Controllers[i].Position; } } guiText = GameObject.Find("gui_text_controller_" + controllerNumber + "_rotation"); if (guiText) { guiText.GetComponent <GUIText>().text = "Rotation = "; if (SixenseInput.Controllers[i].Enabled) { guiText.GetComponent <GUIText>().text += SixenseInput.Controllers[i].Rotation; } } } } }
protected new void UpdateRotation(SixenseInput.Controller controller) { if (LookAtCue){ this.gameObject.transform.LookAt(cueBall.transform); } else{ this.gameObject.transform.localRotation = m_initialRotation * controller.Rotation * m_modelRotation; } }
protected void UpdateMovement() { // Get the input vector from keyboard or analog stick directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); // Get the input vector from OVR positional tracking if (StorageManager.data.optionControlsRiftPosTrackMove || StorageManager.data.optionControlsRiftPosTrackJump) { curPosTrackDir = mainCamera.transform.localPosition; diffPosTrackDir = curPosTrackDir - initPosTrackDir; } if (StorageManager.data.optionControlsRiftPosTrackMove && HMDPresent) { if (diffPosTrackDir.x <= -ovrControlMinimum.x || diffPosTrackDir.x >= ovrControlMinimum.x) { if (ovrXAxisAction == OvrXAxisAction.Strafe) { diffPosTrackDir.x *= ovrControlSensitivity.x; } else { transform.Rotate(0, diffPosTrackDir.x * ovrControlSensitivity.x, 0); diffPosTrackDir.x = 0; } } else { diffPosTrackDir.x = 0; } if (diffPosTrackDir.z <= -ovrControlMinimum.z || diffPosTrackDir.z >= ovrControlMinimum.z) { diffPosTrackDir.z *= ovrControlSensitivity.z; } else { diffPosTrackDir.z = 0; } directionVector = new Vector3(diffPosTrackDir.x, 0, diffPosTrackDir.z); } // Get the input vector from hydra SixenseInput.Controller hydraLeftController = SixenseInput.GetController(SixenseHands.LEFT); SixenseInput.Controller hydraRightController = SixenseInput.GetController(SixenseHands.RIGHT); if (hydraLeftController != null) { directionVector = new Vector3(hydraLeftController.JoystickX, 0, hydraLeftController.JoystickY); } if (jumpEnabled) { if (hydraRightController != null) { motor.inputJump = hydraRightController.GetButton(SixenseButtons.BUMPER); } else if (StorageManager.data.optionControlsRiftPosTrackJump && HMDPresent) { motor.inputJump = GetPositionalTrackingYForJump(); } else { motor.inputJump = Input.GetButton("Jump"); } } // Play jumping audio clips if (initialJumpAudioClips.Length > 0 && motor.inputJump && motor.grounded && !GetComponent <AudioSource>().isPlaying) { GetComponent <AudioSource>().clip = initialJumpAudioClips[UnityEngine.Random.Range(0, initialJumpAudioClips.Length)]; GetComponent <AudioSource>().Play(); } if (directionVector != Vector3.zero) { // Get the length of the directon vector and then normalize it // Dividing by the length is cheaper than normalizing when we already have the length anyway float directionLength = directionVector.magnitude; directionVector = directionVector / directionLength; // Make sure the length is no bigger than 1 directionLength = Mathf.Min(1, directionLength); // Make the input vector more sensitive towards the extremes and less sensitive in the middle // This makes it easier to control slow speeds when using analog sticks directionLength = directionLength * directionLength; // Multiply the normalized direction vector by the modified length directionVector = directionVector * directionLength; } motor.inputMoveDirection = mainCamera.transform.rotation * directionVector; }