예제 #1
0
        // ------------------------------------------------------- Jumping Methods -------------------------------------------------------

        // Using the average vector over the last 'lookBackWindowInSeconds' between two hands, determines the direction in which to make the player jump.
        private void jump(TrackedHand left, TrackedHand right)
        {
            Debug.Log("Jumped");
            Vector3 leftMovementVector  = left.getPosition() - left.pastControllerPositions[left.getIndexForPastTimeSeconds(lookBackWindowInSeconds) - 1].position;
            Vector3 rightMovementVector = right.getPosition() - right.pastControllerPositions[left.getIndexForPastTimeSeconds(lookBackWindowInSeconds) - 1].position;
            Vector3 midway          = leftMovementVector.normalized + rightMovementVector.normalized;
            float   averageVelocity = (left.getVelocity().magnitude + right.getVelocity().magnitude) / 2.0f;

            spawnJumpRock(midway, averageVelocity);
            playerRigidBody.AddForce(-1f * midway.normalized * averageVelocity * jumpSpeed);;
        }
예제 #2
0
        IEnumerator rockAbilityCoroutine(GameObject obj, float speed, TrackedHand hand, float rockForwardFloatDistance)
        {
            yield return(floatInFrontOfHand(obj, hand, rockForwardFloatDistance));

            Debug.Log("rock sequence complete");
            if (rockObject != null)
            {
                rockObject.GetComponent <Rigidbody> ().useGravity = true;
                rockObject.GetComponent <Rigidbody> ().drag       = 0f;
            }
            resetRockAbility();
        }
예제 #3
0
 private void analyzeDynamicGestures()
 {
     if (!abilityActivated)
     {
         // Check wall making gesture
         if (bothFistsMovingUp() && !isJumping)
         {
             Debug.Log("Triggering wall summon!");
             abilityActivated = true;
             wallIsMaking     = true;
             summonWall();
         }
         // Check Jumping ability
         if (bothFistsMovingDown() && !isJumping)
         {
             Debug.Log("Triggering jump!");
             abilityActivated = true;
             jump(leftHand, rightHand);
         }
         // Check rock lifting gesture
         else if (isFistAndMovingUp(leftHand) && bothHandsGestureTimer <= 0.0)
         {
             Debug.Log("Triggering left rock summon!");
             abilityActivated = true;
             rockIsActive     = true;
             summonRock(leftHand);
         }
         else if (isFistAndMovingUp(rightHand) && bothHandsGestureTimer <= 0.0)
         {
             Debug.Log("Triggering right rock summon!");
             abilityActivated         = true;
             rockIsActive             = true;
             rightHandAbilityIsActive = true;
             summonRock(rightHand);
         }
     }
     else if (rockObject != null && abilityActivated && rockIsActive)
     {
         TrackedHand punchingHand = rightHandAbilityIsActive ? leftHand : rightHand;
         if (isFistAndMovingInDirection(punchingHand, lookBackWindowInSeconds, rockObject.transform.position - punchingHand.getPosition(), punchDistanceThreshold))
         {
             if ((rockObject.transform.position - punchingHand.getPosition()).magnitude < rockPunchActivationDistance)
             {
                 Debug.Log("Triggering rock punch!");
                 rockIsActive = false;
                 punchRock(rockObject.transform.position - punchingHand.pastControllerPositions[punchingHand.getIndexForPastTimeSeconds(lookBackWindowInSeconds) - 1].position, punchingHand.getVelocity().sqrMagnitude * 250f);
             }
         }
     }
 }
예제 #4
0
        IEnumerator floatInFrontOfHand(GameObject obj, TrackedHand hand, float forwardDistance)
        {
            while (obj != null && rockIsActive && recognizePlayerFist(hand))
            {
                Vector3 finalPosition = hand.getFloatingPositionInFrontOfHand(forwardDistance);

                if (Vector3.Distance(obj.transform.position, finalPosition) > floatMovementThreshold)
                {
                    Vector3 direction = finalPosition - obj.transform.position;
                    obj.GetComponent <Rigidbody> ().AddForce(direction * floatSpeed);
                }

                yield return(null);
            }
        }
예제 #5
0
        void Start()
        {
            // Object instantiation
            player          = GetComponent <Player> ();
            playerRigidBody = GetComponent <Rigidbody> ();
            leftHand        = new TrackedHand(player.leftHand);
            rightHand       = new TrackedHand(player.rightHand);
            terrainLayer    = LayerMask.NameToLayer("Terrain");

            // Start repeating processes
            InvokeRepeating("UpdateAtInterval", 0, handPositionMemoryInterval);

            // TODO: Move the below to a game manager script
            // SteamVR housekeeping
            Teleport.instance.CancelTeleportHint();
        }
예제 #6
0
        private bool recognizePlayerFist(TrackedHand hand)
        {
            if (hand == null)
            {
                return(false);
            }

            SteamVR_Behaviour_Skeleton skeleton = hand.getSkeleton();

            if (skeleton != null)
            {
                return(hand.recognizeFist());
            }

            return(abilityActivated);
        }
예제 #7
0
        private bool isFistAndMovingInDirection(TrackedHand hand, float lookBackWindowInSeconds, Vector3 direction, float distanceThreshold)
        {
            int lookBackWindowIndex = hand.getIndexForPastTimeSeconds(lookBackWindowInSeconds);

            // Validate that we have enough position memory
            if (hand.pastControllerPositions.Count < lookBackWindowIndex)
            {
                // Debug.Log("Not enough look back positions");
                return(false);
            }

            for (int i = 0; i < lookBackWindowIndex; i++)
            {
                // Validate validity requirement
                if (!hand.pastControllerPositions[i].isValid)
                {
                    // Debug.Log("Not enough valid look back positions");
                    return(false);
                }

                // Validate grip requirement
                if (!hand.pastControllerPositions[i].isGripping)
                {
                    // Debug.Log("Hands were not gripped long enough");
                    return(false);
                }

                // Validate distance travelled requirement
                Vector3 distanceTravelled            = hand.getPosition() - hand.pastControllerPositions[i].position;
                float   distanceTravelledInDirection = Vector3.Dot(distanceTravelled, direction.normalized);
                if (distanceTravelledInDirection > distanceThreshold)
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #8
0
        private void summonRock(TrackedHand hand)
        {
            GameObject rock = spawnRock();

            StartCoroutine(rockAbilityCoroutine(rock, rockSummonSpeed, hand, rockForwardFloatDistance));
        }
예제 #9
0
 private bool isFistAndMovingDown(TrackedHand hand)
 {
     return(isFistAndMovingInDirection(hand, lookBackWindowInSeconds, Vector3.down, jumpGestureMoveDistanceThreshold));
 }
예제 #10
0
 private bool isFistAndMovingUp(TrackedHand hand)
 {
     return(isFistAndMovingInDirection(hand, lookBackWindowInSeconds, Vector3.up, verticalMoveDistanceThreshold));
 }