Пример #1
0
    // 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;
            }
        }
    }
Пример #2
0
    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;
            }
        }
    }
Пример #3
0
 // Update is called once per frame
 void Update()
 {
     if (SixenseInput.GetController(SixenseHands.LEFT).GetButtonDown(SixenseButtons.BUMPER))
     {
         Destroy(this.gameObject);
     }
 }
Пример #4
0
    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);
    }
Пример #5
0
 protected void Update()
 {
     if (m_controller == null)
     {
         m_controller = SixenseInput.GetController(m_hand);
     }
 }
Пример #6
0
    // 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);
        }
    }
Пример #7
0
 // 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);
 }
Пример #8
0
    protected void Update()
    {
        if (m_controller == null)
        {
            m_controller = SixenseInput.GetController(m_hand);
        }

        else if (m_animator != null)
        {
            UpdateHandAnimation();
        }
    }
Пример #9
0
    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));
            }
            //}
        }
    }
Пример #10
0
    // 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);
        }
    }
Пример #11
0
    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);
    }
Пример #13
0
    // 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);
    }
Пример #14
0
    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;
        }
    }
Пример #15
0
    // 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);
        }
    }
Пример #16
0
        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());
            }
        }
Пример #17
0
    /*
     * 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);
    }
Пример #18
0
        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;
            }
        }
Пример #19
0
    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);
    }
Пример #20
0
    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);
    }
Пример #21
0
    // 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);
    }
Пример #22
0
    // 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)
            {
                Vector3 middle = (l + r) * .5f;
                Vector3 axis   = middle - gameObject.transform.position;
                Vector3 angle  = Vector3.Cross((rPrev - lPrev), (r - l)) * 200 / (middle.magnitude);
                //axis.Normalize();
                //axis.Scale(new Vector3(angle, angle, angle));
                rotSpeed = angle;
            }
            else if (lDown)
            {
                Vector3 v1 = (l - lPrev);
                Vector3 v2 = (l - gameObject.transform.position);
                lDown    = true;
                rDown    = false;
                rotSpeed = Vector3.Cross(v2, v1) / v2.magnitude;
            }
            else if (rDown)
            {
                Vector3 v1 = (r - rPrev);
                Vector3 v2 = (r - gameObject.transform.position);
                rDown    = true;
                lDown    = false;
                rotSpeed = Vector3.Cross(v2, v1) / v2.magnitude;
            }

            gameObject.renderer.material.color = new Color(1, 1 - rotSpeed.magnitude / 5,
                                                           1 - rotSpeed.magnitude / 5, gameObject.renderer.material.color.a);

            lPrev = l;
            rPrev = r;
        }

        //gameObject.transform.Rotate(rotSpeed);
        gameObject.transform.RotateAround(rotSpeed, rotSpeed.magnitude / 10);
        rotSpeed = rotSpeed * .7f;
        //rotSpeed = new Vector3(0, 1, 0);
    }
Пример #23
0
    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;
        }
    }
Пример #24
0
    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;
    }
Пример #25
0
    // 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";
                }
            }
        }
    }
Пример #26
0
    // 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> ();
                }
            }
        }
    }
Пример #27
0
    // 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;
        }
    }
Пример #28
0
 protected void Update()//override SixenseObjectController Update
 {
     _controller = SixenseInput.GetController(Hand);
     if (_controller != null && _controller.Enabled)
         UpdateHandAnimation();
 }