Exemplo n.º 1
0
    protected void UpdateActionInput(SixenseInput.Controller controller)
    {
        Vector3    currentPosition = GetCurrentColliderPosition();
        Quaternion currentRotation = GetCurrentColliderRotation();

        Velocity();

        if (isHoldingObject && !controller.GetButton(SixenseButtons.TRIGGER))
        {
            Throw();

            isHoldingObject = false;
        }

        if (!isHoldingObject)
        {
            foreach (GameObject o in GameObject.FindGameObjectsWithTag("Grabbable"))
            {
                float dist = Vector3.Distance(o.transform.position, currentPosition);
                if (dist < minGrabDistance)
                {
                    closestObject = o;
                }
            }
        }

        if ((isHoldingObject && controller.GetButton(SixenseButtons.TRIGGER)) ||
            (closestObject != null && Vector3.Distance(closestObject.transform.position, currentPosition) < minGrabDistance && controller.GetButton(SixenseButtons.TRIGGER)))
        {
            if (closestObject.GetComponent <Rigidbody>() && closestObject.GetComponent <Rigidbody>().isKinematic)
            {
                return;
            }

            grabObject = closestObject.GetComponent <GrabObject>();
            if (grabObject && grabObject.isEnabled)
            {
                grabObject.SetRigidbodyDetectionCollisions(false);
                closestObject.transform.position = currentPosition + closestObject.transform.TransformDirection(grabObject.GetPosition(Hand));
                closestObject.transform.rotation = currentRotation * Quaternion.Euler(grabObject.GetRotation(Hand));
            }
            else
            {
                closestObject.transform.position = currentPosition;
                closestObject.transform.rotation = currentRotation;
            }

            isHoldingObject = true;
        }
    }
Exemplo n.º 2
0
    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);
        }
    }
Exemplo n.º 3
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;
            }
        }
    }
Exemplo n.º 4
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);
    }
Exemplo n.º 5
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);
    }
Exemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        leftHydra  = SixenseInput.Controllers [0];
        rightHydra = SixenseInput.Controllers [1];
        cooldown  -= Time.deltaTime;
        //Debug.Log (cooldown);

#if UNITY_ANDROID
        if (f_timeSinceLastDoubleTouch > 0.0f)
#else
        if ((leftHydra.GetButton(SixenseButtons.BUMPER) && rightHydra.GetButton(SixenseButtons.BUMPER)) || Input.GetAxis("Fire1") > 0.0f)
#endif
        {
            cooldown = 3.0f;
        }

        checkTouch();
    }
Exemplo n.º 7
0
    public void OnAnimatorIK()
    {
        turningDeadTime -= Time.deltaTime;

        leftController = SixenseInput.GetController( SixenseHands.LEFT );
        rightController = SixenseInput.GetController( SixenseHands.RIGHT );

        if ( leftController == null || rightController == null )
        {
            ChangeToState( State.Standing );
            return;
        }

        bool leftTriggerActive = leftController.GetButton( SixenseButtons.TRIGGER );
        bool rightTriggerActive = rightController.GetButton( SixenseButtons.TRIGGER );

        if ( leftTriggerActive && rightTriggerActive )
            ChangeToState ( State.Turning );
        else if ( leftTriggerActive )
            ChangeToState ( State.LeftFootPushes );
        else if ( rightTriggerActive )
            ChangeToState( State.RightFootPushes );
        else
            ChangeToState( State.Standing );

        switch ( state )
        {
            case State.Turning:
                if ( turningDeadTime <= 0 )
                    Turn();
                break;

            case State.LeftFootPushes:
                PushFootLeft();
                break;

            case State.RightFootPushes:
                PushFootRight();
                break;
        }

        lastLeftPos = leftController.Position;
        lastRightPos = rightController.Position;
    }
Exemplo n.º 8
0
    public override bool SelectionButtonIsDown()
    {
        if (razer == null || !razer.Enabled)
        {
            return(false);
        }
        switch (selectionButton)
        {
        case SixenseButtons.BUMPER:
            return(razer.GetButton(SixenseButtons.BUMPER));

        case SixenseButtons.FOUR:
            return(razer.GetButton(SixenseButtons.FOUR));

        case SixenseButtons.JOYSTICK:
            return(razer.GetButton(SixenseButtons.JOYSTICK));

        case SixenseButtons.ONE:
            return(razer.GetButton(SixenseButtons.ONE));

        case SixenseButtons.START:
            return(razer.GetButton(SixenseButtons.START));

        case SixenseButtons.THREE:
            return(razer.GetButton(SixenseButtons.THREE));

        case SixenseButtons.TRIGGER:
            return(razer.GetButton(SixenseButtons.TRIGGER));

        case SixenseButtons.TWO:
            return(razer.GetButton(SixenseButtons.TWO));

        default:
            return(false);
        }
    }
Exemplo n.º 9
0
    public void InAttackRange(GameObject animal)
    {
        if (cooldown <= 0.0f)
        {
#if UNITY_ANDROID
            if (f_timeSinceLastDoubleTouch > 0.0f)
#else
            if ((leftHydra.GetButton(SixenseButtons.BUMPER) && rightHydra.GetButton(SixenseButtons.BUMPER)) || Input.GetAxis("Fire1") > 0.0f)
#endif
            {
                Debug.Log("Attack Succesfull!");
                animal.transform.parent = this.transform;
                animal.GetComponentInChildren <Prey> ().enabled = false;
                Rigidbody animalRigidBody = animal.GetComponent <Rigidbody> ();
                animalRigidBody.constraints = RigidbodyConstraints.FreezeAll;
                animalRigidBody.GetComponent <Rigidbody> ().detectCollisions = false;
                animalRigidBody.GetComponent <Rigidbody> ().useGravity       = false;
                animal.transform.localPosition = Vector3.zero;
                animal.GetComponentInChildren <MeshCollider> ().enabled = false;
                //Destroy(animal.gameObject);
            }
        }
    }
Exemplo n.º 10
0
    // 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;
        }
    }
Exemplo n.º 11
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;
        }
    }
Exemplo n.º 12
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> ();
                }
            }
        }
    }
Exemplo n.º 13
0
    /* Razer Hydra Tutorial____________________________________
    |
    | https://www.slideshare.net/cjros/basic-vr-development-tutorial-integrating-oculus-rift-and-razer-hydra
    |__________________________________________________________*/

    public bool IsPointing()
    {
        if(_controller == null)
            return false;
        return _controller.GetButton(SixenseButtons.TRIGGER);
    }
Exemplo n.º 14
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";
                }
            }
        }
    }
Exemplo n.º 15
0
    // 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);
        }
    }
Exemplo n.º 16
0
    // Update is called once per frame
    void Update()
    {
        if (controller == null)
        {
            return;
        }

        transform.position = controller.Position * scale;

        if (controller.Trigger > 0.3f)
        {
            if (started)
            {
                ChunkManager.Instance.Draw(controller.Position * scale, radius * controller.Trigger, color);
                saved = false;
            }
        }
        else
        {
            // when clicking trigger to initialize controller, the first draw is always an error.
            started = true;
        }

        if (controller.GetButton(SixenseButtons.BUMPER))
        {
            ChunkManager.Instance.Drag(controller.Position * scale,
                                       (controller.Position - lastPosition) * scale,
                                       controller.Rotation * Quaternion.Inverse(lastRotation));
        }

        lastPosition = controller.Position;
        lastRotation = controller.Rotation;

        if (controller.GetButtonDown(SixenseButtons.START))
        {
            ChunkManager.Instance.SaveChunks(scene + ".vox");
            saved = true;
        }

        if (saved)
        {
            bool load = false;
            if (controller.GetButtonDown(SixenseButtons.ONE))
            {
                load  = true;
                scene = 1;
            }
            if (controller.GetButtonDown(SixenseButtons.TWO))
            {
                load  = true;
                scene = 2;
            }
            if (controller.GetButtonDown(SixenseButtons.THREE))
            {
                load  = true;
                scene = 3;
            }
            if (controller.GetButtonDown(SixenseButtons.FOUR))
            {
                load  = true;
                scene = 4;
            }

            if (load)
            {
                ChunkManager.Instance.LoadChunks(scene + ".vox");
            }
        }

        var joystick = new Vector2(controller.JoystickX, controller.JoystickY);

        if (joystick.sqrMagnitude > 0.4f)
        {
            if (lastThumb.sqrMagnitude < 0.5f)
            {
                lastThumb = joystick.normalized;
            }

            if (Mathf.Abs(Vector3.Cross(joystick.normalized, lastThumb).z) > 0.5f)
            {
                int c = color + Mathf.RoundToInt(Mathf.Sign(Vector3.Cross(joystick.normalized, lastThumb).z));
                lastThumb = joystick.normalized;

                if (c < 0)
                {
                    c = (byte)(MarchingCubes.Builder.colorMap.Length - 1);
                }
                if (c >= MarchingCubes.Builder.colorMap.Length)
                {
                    c = 0;
                }

                color = (byte)c;

                material.color = MarchingCubes.Builder.colorMap[color];
            }
        }
        else
        {
            lastThumb = Vector2.zero;
        }
    }
Exemplo n.º 17
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);
    }
    void FixedUpdate()
    {
        //characterController.ApplyForceInCharacterDirection(translation);
		
		float locomotionScale = Mathf.Max(transform.lossyScale.x, transform.lossyScale.z);

        direction = 0;
		turnMagnitude = 0;
		
		if(characterController != null)
		{
			grounded  = characterController.grounded;
			colliding = characterController.colliding;
		}
		
		if(grounded || colliding)
		{
			airborne = false;
		}
		else
		{
			if(!airborne)
			{
				jumpTimeVelocity = GetComponent<Rigidbody>().velocity;
				jumpTimeVelocity.y = 0;
				jumpTimeVelocity = Vector3.ClampMagnitude(jumpTimeVelocity, aerialMobility*speed*locomotionScale);
				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*locomotionScale;

        velocity = GetComponent<Rigidbody>().velocity;
        velocityChange = (targetVelocity - velocity);

        velocityChange.y = 0;
		velocityChange = Vector3.ClampMagnitude(velocityChange, Time.fixedDeltaTime * maxVelocityChange * locomotionScale);
		
		if(!airborne)
		{
        	GetComponent<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) * locomotionScale;

			// 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* locomotionScale)
			{
				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*locomotionScale)
			{
				GetComponent<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)
		{
			GetComponent<Rigidbody>().AddForce(
				new Vector3(0, Mathf.Sqrt((1 + 0.5f*(controlDirection.magnitude + extraSpeed)*jumpSpeedEffect)*jumpStrength*locomotionScale)
								* GetComponent<Rigidbody>().mass, 0), ForceMode.Impulse);
			if(characterController)
				characterController.lastJumpTime = Time.fixedTime;
			
            shouldJump = false;
        }
		
    }
Exemplo n.º 19
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;
    }
Exemplo n.º 20
0
    // Updates the animated object from controller input.
    protected void UpdateHandAnimation()
    {
        // Point
        if (m_hand == SixenseHands.RIGHT ? m_controller.GetButton(SixenseButtons.ONE) : m_controller.GetButton(SixenseButtons.TWO))
        {
            m_animator.SetBool("Point", true);
        }
        else
        {
            m_animator.SetBool("Point", false);
        }

        // Grip Ball
        if (m_hand == SixenseHands.RIGHT ? m_controller.GetButton(SixenseButtons.TWO) : m_controller.GetButton(SixenseButtons.ONE))
        {
            m_animator.SetBool("GripBall", true);
        }
        else
        {
            m_animator.SetBool("GripBall", false);
        }

        // Hold Book
        if (m_hand == SixenseHands.RIGHT ? m_controller.GetButton(SixenseButtons.THREE) : m_controller.GetButton(SixenseButtons.FOUR))
        {
            m_animator.SetBool("HoldBook", true);
        }
        else
        {
            m_animator.SetBool("HoldBook", false);
        }

        // Fist
        float fTriggerVal = m_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);
            m_animator.SetBool("Point", true);
        }
        else
        {
            //m_animator.SetBool("Idle", false);
            m_animator.SetBool("Point", true);
        }
    }
Exemplo n.º 21
0
    void CalculateMovementSpeed(SixenseInput.Controller leftHydra, SixenseInput.Controller rightHydra)
    {
        if (rightHydra.GetButtonDown(SixenseButtons.BUMPER) || Input.GetButtonDown("SneakToggle"))
        {
            ToggleSneak();
        }

        if (rightHydra.GetButton(SixenseButtons.TRIGGER) || leftHydra.GetButton(SixenseButtons.TRIGGER) || Input.GetButton("Jump"))
        {
            if (((rightHydra.GetButton(SixenseButtons.TRIGGER) && leftHydra.GetButton(SixenseButtons.TRIGGER)) || Input.GetButton("Sprint")) && f_sprintEnergy > 0.0f)
            {
                f_maxSpeed      = 0.5f;
                f_sprintEnergy -= Time.deltaTime;
                f_speed        += Time.deltaTime * 1.5f;
                if (b_sneaking)
                {
                    ToggleSneak();
                }
                //print ("SPRINT");
            }
            else if (b_sneaking)
            {
                f_maxSpeed      = 0.15f;
                f_sprintEnergy += Time.deltaTime;
                f_speed        += Time.deltaTime;
                //print ("SNEAK");
            }
            else if (rightHydra.Rotation.x < -0.4f && leftHydra.Rotation.x < -0.4f || Input.GetAxis("Vertical") < 0.0f)
            {
                f_minSpeed = -0.15f;
                f_speed   -= Time.deltaTime;
            }
            else if (f_maxSpeed > 0.5f)
            {
                f_maxSpeed -= Time.deltaTime;
            }
            else
            {
                f_maxSpeed      = 0.25f;
                f_sprintEnergy += Time.deltaTime / 2;
                f_speed        += Time.deltaTime;
                //print ("WALK");
            }
        }
        else
        {
            f_sprintEnergy += Time.deltaTime;
            f_speed        -= Time.deltaTime * 2.0f;
            if (f_minSpeed < 0.0f)
            {
                f_minSpeed += Time.deltaTime;
            }
            else
            {
                f_minSpeed = 0.0f;
            }
            //print ("STAND");
        }

        Mathf.Clamp(f_sprintEnergy, 0.0f, 10.0f);
        f_speed = Mathf.Clamp(f_speed, f_minSpeed, f_maxSpeed);
    }