Esempio n. 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);;
        }
Esempio n. 2
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);
             }
         }
     }
 }