Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (!photonView.IsMine)
        {
            return;
        }

        Vector3 handPos = PoseParser.GETLeftHandPositionAsVector();

        // if confidence is over 90%
        if (handPos.z > 0.15)
        {
            // normalise
            // TODO don't hard code values
            handPos.Scale(new Vector3(1.0f / 320.0f, 1.0f / 240.0f, 0));
            // rescale onto screen (this is far from perfect due to odd UI scaling)
            crosshairTransform.anchoredPosition = new Vector2((-2.0f * handPos.x * 240) + 580, (-2.0f * handPos.y * 240) + 300);
        }
        else
        {
            crosshairTransform.anchoredPosition = origionalPosition;
        }

        // Debug.Log("CROSSHAIR = " + crosshairTransform.anchoredPosition.ToString());
    }
Esempio n. 2
0
 void Update()
 {
     if (!hasAuthority)
     {
         return;
     }
     txtMy.text = PoseParser.GETGestureAsString() + string.Join(",", PoseParser.GETPoseArray());
 }
Esempio n. 3
0
 void Start()
 {
     if (!hasAuthority)
     {
         return;
     }
     txtMy.text = string.Join(",", PoseParser.GETPoseArray());
 }
    IEnumerator SetFaceActive()
    {
        if (check == false)
        {
            faceUI.SetActive(true);
        }
        yield return(new WaitForSeconds(2));

        if (Input.GetKeyDown(KeyCode.LeftControl) || PoseParser.GETGestureAsString().CompareTo("C") == 0)
        {
            faceUI.SetActive(false);
            check = true;
        }
    }
Esempio n. 5
0
    // Update is called once per frame
    void Update()
    {
        if (!photonView.IsMine)
        {
            return;
        }
        // update gesture
        string tempGesture = PoseParser.GETGestureAsString();

        if (tempGesture != gesture)
        {
            gesture = tempGesture;
        }
        //Debug.Log(gesture);
    }
 // Start is called before the first frame update
 void Start()
 {
     // gets the gesture from PoseParser
     gesture = PoseParser.GETGestureAsString();
     // if photon view is player's, sets their local UI to active
     if (photonView.IsMine)
     {
         playerUI.SetActive(true);
     }
     // if UI is not the player's, disable it
     if (!photonView.IsMine && GetComponent <PlayerMovementPhoton>() != null)
     {
         Debug.Log(" DISABLE CONTROLER ");
         playerUI.SetActive(false);
     }
 }
Esempio n. 7
0
    // Update is called once per frame
    void Update()
    {
        if (!photonView.IsMine)
        {
            return;
        }
        poseArr        = PoseParser.GETPoseArray();
        currentNosePos = new Vector3(poseArr[0], poseArr[1], 0);

        noseOffset = currentNosePos - origionalNosePos;
        noseOffset.Scale(new Vector3(-1.0f / 240.0f, -1.0f / 240.0f, 1.0f / 240.0f));

        //Debug.Log(noseOffset.ToString());

        //cameraTransform.localPosition = origionalTranfromPos + noseOffset;
        photonView.RPC("newHeadPos", RpcTarget.All);
    }
Esempio n. 8
0
    // Start is called before the first frame update
    void Start()
    {
        // gets the gesture from PoseParser
        gesture = PoseParser.GETGestureAsString();
        // if photon view is player's, sets their local UI to active
        if (photonView.IsMine)
        {
            playerUI.SetActive(true);
        }
        // if UI is not the player's, disable it
        if (!photonView.IsMine && GetComponent <PlayerMovementPhoton>() != null)
        {
            //Debug.Log(" DISABLE CONTROLER ");
            playerUI.SetActive(false);
            Destroy(playerMenu);
        }

        soundSources = GameObject.FindGameObjectWithTag("Songs");
        soundSources.transform.GetChild(0).GetComponent <AudioSource>().Play();
    }
Esempio n. 9
0
    // Update is called once per frame
    void Update()
    {
        if (cinemachineBrain.ActiveVirtualCamera as CinemachineVirtualCamera != Camera.GetComponent <CinemachineVirtualCamera>())
        {
            return;
        }

        bool canInteract = interactableInRange && !character.HasItem();

        if (canInteract)
        {
            Interactable newInteractable = null;

            try
            {
                newInteractable = interactableObject.GetComponent <Interactable>();
            }
            catch
            {
                //Debug.Log("Interactable is null");
            }


            //currentInteractable = newInteractable;

            if (newInteractable != null)
            {
                //Debug.Log("current interactable has a pick up script");
                if (((Input.GetKeyDown(KeyCode.E) || PoseParser.GETGestureAsString().CompareTo("P") == 0)))
                {
                    if (newInteractable.GetComponent <Breakable>() != null)
                    {
                        //photonView.RPC("SetBreakHandsInactive", GetComponent<PhotonView>().Owner);
                        SetBreakHandsInactive();
                        newInteractable.PrimaryInteraction(character);
                        return;
                    }
                }
                //d is for opening
                //u is closing

                if (Input.GetKeyDown(KeyCode.E))
                {
                    if (newInteractable.GetComponent <Openable>() != null)
                    {
                        newInteractable.PrimaryInteraction(character);
                        return;
                    }
                }

                if (PoseParser.GETGestureAsString().CompareTo("D") == 0)
                {
                    if (newInteractable.GetComponent <Openable>() != null && newInteractable.GetComponent <Openable>().isOpened == false)
                    {
                        newInteractable.PrimaryInteraction(character);
                        return;
                    }
                }

                if (PoseParser.GETGestureAsString().CompareTo("U") == 0)
                {
                    if (newInteractable.GetComponent <Openable>() != null && newInteractable.GetComponent <Openable>().isOpened == true)
                    {
                        newInteractable.PrimaryInteraction(character);
                        return;
                    }
                }

                if ((Input.GetKeyDown(KeyCode.E) || PoseParser.GETGestureAsString().CompareTo("B") == 0) && newInteractable.GetComponent <Breakable>() == null && newInteractable.GetComponent <Openable>() == null)
                {
                    if (newInteractable.GetComponent <Switchable>() != null)
                    {
                        newInteractable.PrimaryInteraction(character);
                    }
                    else if (newInteractable.GetComponent <Droppable>() != null)
                    {
                        newInteractable.PrimaryInteraction(character);
                        //photonView.RPC("SetPressDropToNotActive", GetComponent<PhotonView>().Owner);
                        SetPressDropToNotActive();
                    }
                    else
                    {
                        currentInteractable = newInteractable;
                        currentInteractable.GetComponent <Outline>().enabled = false;
                        // Debug.Log("F was pressed");

                        currentInteractable.PrimaryInteraction(character);
                    }
                }
            }
        }
        // if we are holding something, we are limited to the possible interactions
        else if (currentInteractable != null)
        {
            // check if there is a bag nearby as we can still pickup bags if we are holding an item
            Grabbable  newBag          = null;
            Switchable newSwitch       = null;
            Droppable  dropBag         = null;
            Breakable  breakableObject = null;
            Openable   openableObject  = null;
            try
            {
                newBag = interactableObject.GetComponent <Grabbable>();
            }
            catch
            {
                //Debug.Log("rock is null");
            }

            try
            {
                newSwitch = interactableObject.GetComponent <Switchable>();
            }
            catch
            {
                //Debug.Log("switch is null");
            }

            try
            {
                dropBag = interactableObject.GetComponent <Droppable>();
            }
            catch
            {
                //Debug.Log("switch is null");
            }

            try
            {
                breakableObject = interactableObject.GetComponent <Breakable>();
            }
            catch
            {
                //Debug.Log("breakable is null");
            }

            try
            {
                openableObject = interactableObject.GetComponent <Openable>();
            }
            catch
            {
                //Debug.Log("Opanable is null");
            }
            if ((Input.GetKeyDown(KeyCode.E) || PoseParser.GETGestureAsString().CompareTo("P") == 0) && openableObject != null)
            {
                openableObject.PrimaryInteraction(character);
            }

            if ((Input.GetKeyDown(KeyCode.E) || PoseParser.GETGestureAsString().CompareTo("B") == 0) && newBag != null)
            {
                newBag.PrimaryInteraction(character);
            }

            if ((Input.GetKeyDown(KeyCode.E) || PoseParser.GETGestureAsString().CompareTo("B") == 0) && newSwitch != null)
            {
                newSwitch.PrimaryInteraction(character);
            }

            if (Input.GetKeyDown(KeyCode.E) && dropBag != null)
            {
                dropBag.PrimaryInteraction(character);
                //photonView.RPC("SetPressDropToNotActive", GetComponent<PhotonView>().Owner);
                SetPressDropToNotActive();
            }

            if (Input.GetKeyDown(KeyCode.E) && breakableObject != null)
            {
                breakableObject.PrimaryInteraction(character);
            }
            // press G to drop/throw item
            if (Input.GetKeyDown(KeyCode.G))
            {
                // we drop/throw item and turn off its outline
                currentInteractable.SecondaryInteraction(character);
                currentInteractable.GetComponent <Outline>().enabled = true;
                currentInteractable = null;
            }
            else

            if ((Input.GetMouseButtonDown(0) || PoseParser.GETGestureAsString().CompareTo("R") == 0) && currentInteractable.GetComponent <Throwable>() != null)
            {
                currentInteractable.GetComponent <Throwable>().ThrowRock(character);
                currentInteractable.GetComponent <Outline>().enabled = true;
                currentInteractable = null;
            }
            else
            // if item is shootable
            if (Input.GetMouseButtonDown(0) && currentInteractable.GetComponent <Shootable>() != null)
            {
                //Debug.Log(currentInteractable);
                currentInteractable.GetComponent <Shootable>().ShootGun(character);
            }
        }
    }
Esempio n. 10
0
    //function that handles all players movement
    void Movement()
    {
        if (onMenu && !onTrain)
        {
            steps.Stop();
            return;
        }

        // Checks if the groundCheck object is within distance to the ground layer
        bool old = isGrounded;

        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

        if (old != isGrounded)
        {
            GetComponent <PlayerAnimation>().setGrounded(isGrounded);
        }

        // Prevents downward velocity from decreasing infinitely if player is on the ground
        if (isGrounded && velocity.y < 0)
        {
            velocity.y = -3f;
        }

        //this handels game ending on the last level. When the player gets on the truck, it doenst take into account movement anymore, just gravity
        if (gameEnding)
        {
            velocity.y += gravity * Time.deltaTime;
            controller.Move(velocity * Time.deltaTime);
            return;
        }

        //get axis
        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");
        float l = Input.GetAxis("Ladder");

        //if the player move for the first time get the achievement baby steps
        if (!babySteps)
        {
            if (x > 0f || z > 0f)
            {
                GetComponent <Achievements>()?.BabyStepsCompleted();
                babySteps = true;
            }
        }

        // instantiates move with null so that it can be set depending on climb
        Vector3 move;

        //if pose is climbing, add the upwards velocity
        if ((climbingBuilding || climbing) && PoseParser.GETGestureAsString().CompareTo("L") == 0)
        {
            move = transform.up * 0.4f;
        }
        else if ((climbingBuilding || climbing) && l > 0f)
        {
            move = transform.up * l;
        }

        //if the pose is move forwards, move forward
        else if (PoseParser.GETGestureAsString().CompareTo("F") == 0)
        {
            move = transform.forward;
        }

        //if pose is move diagonal right, move diagonal right
        else if (PoseParser.GETGestureAsString().CompareTo("I") == 0)
        {
            move = transform.right + transform.forward;
        }

        //if pose is move diagonal left, move diagonal left
        else if (PoseParser.GETGestureAsString().CompareTo("O") == 0)
        {
            move = transform.right * -1 + transform.forward;
        }
        else
        {
            move = transform.right * x + transform.forward * z;
        }

        //if climbing, translate the player up
        if (climbing || climbingBuilding)
        {
            timerCountDown -= Time.deltaTime;
            if (timerCountDown < 0)
            {
                timerCountDown = 0;
            }

            transform.Translate(Vector3.up * Input.GetAxis("Vertical") * 2 * Time.deltaTime);
        }


        //move the player according to the controller
        controller.Move(move * speed * Time.deltaTime);

        // Checks if jump button is pressed and allows user to jump if they are on the ground
        if (Input.GetButtonDown("Jump") && isGrounded && !crouching)
        {
            onTrain = false;
            faceUI.SetActive(false);
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
        }

        //Toggle crouch animation if alt
        if ((Input.GetKeyDown(KeyCode.LeftControl) || PoseParser.GETGestureAsString().CompareTo("C") == 0) && !crouching)
        {
            crouching = true;
            faceUI.SetActive(false);
            controller.height = 1.2f;
        }
        else if ((Input.GetKeyDown(KeyCode.LeftControl) || PoseParser.GETGestureAsString().CompareTo("N") == 0) && crouching)
        {
            crouching         = false;
            controller.height = 1.8f;
        }

        //velocity.y += gravity * Time.deltaTime;
        // Only applies gravity when not climbing, this allows players to stay on ladder
        if (!climbing && !climbingBuilding)
        {
            velocity.y += gravity * Time.deltaTime;
            controller.Move(velocity * Time.deltaTime);
        }


        //if player is on the train
        if ((move.x != 0 || move.z != 0) && isGrounded && !onTrain)
        {
            if (crouching)
            {
                steps.Stop();
                run.Stop();
                return;
            }

            if (!steps.isPlaying && speed == 4.0f)
            {
                steps.Play();
                run.Stop();
            }
            else if (!run.isPlaying && speed == 8.0f)
            {
                run.Play();
                steps.Stop();
            }
        }
        else
        {
            steps.Stop();
            run.Stop();
        }
    }
Esempio n. 11
0
    private void Animate()
    {
        //Debug.Log("____");

        bool isWalking     = animator.GetBool(isWalkingHash);
        bool isJumping     = animator.GetBool(isJumpingHash);
        bool isRunningBack = animator.GetBool(isRunningBackHash);
        bool isRunning     = animator.GetBool(isRunningHash);
        bool isLeft        = animator.GetBool(isLeftHash);
        bool isRight       = animator.GetBool(isRightHash);
        bool isCrouched    = animator.GetBool(isCrouchedHash);
        bool isClimbing    = animator.GetBool(isClimbingHash);

        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");

        //Debug.Log("Initial isCrouched:"+crouching);
        // Debug.Log(climbing + " XDDD " + Input.GetKeyDown(KeyCode.W));

        if (climbing && (Input.GetButton("Ladder") || PoseParser.GETGestureAsString().CompareTo("L") == 0))
        {
            animator.SetBool(isClimbingHash, true);
        }
        else
        {
            animator.SetBool(isClimbingHash, false);
        }

        if (!isWalking && (z > 0.02f || PoseParser.GETGestureAsString().CompareTo("F") == 0))
        {
            if (Input.GetKey(KeyCode.LeftShift) || PoseParser.GETGestureAsString().CompareTo("F") == 0)
            {
                //Debug.Log("running");
                animator.SetBool(isRunningHash, true);
                player.setSpeed(runningSpeed);
            }

            else if (!crouching)
            {
                //Debug.Log("walking");
                animator.SetBool(isWalkingHash, true);
                player.setSpeed(walkingSpeed);
            }
        }
        if (!isRunningBack && z < -0.02f)
        {
            animator.SetBool(isRunningBackHash, true);
        }
        if (z <= 0.02f && z >= -0.02f && PoseParser.GETGestureAsString().CompareTo("F") != 0)
        {
            animator.SetBool(isWalkingHash, false);
            animator.SetBool(isRunningHash, false);
            animator.SetBool(isRunningBackHash, false);
        }
        if ((!isRight && x > 0.02f) || (!isRight && PoseParser.GETGestureAsString().CompareTo("I") == 0))
        {
            animator.SetBool(isRightHash, true);
        }
        if (x <= 0.02f && x >= -0.02f && PoseParser.GETGestureAsString().CompareTo("I") != 0 && PoseParser.GETGestureAsString().CompareTo("O") != 0)
        {
            animator.SetBool(isLeftHash, false);
            animator.SetBool(isRightHash, false);
        }
        if ((!isLeft && x < -0.02f) || (!isLeft && PoseParser.GETGestureAsString().CompareTo("O") == 0))
        {
            animator.SetBool(isLeftHash, true);
        }

        // if ((Input.GetKeyDown(KeyCode.LeftShift) || PoseParser.GETGestureAsString().CompareTo("F") == 0) && isCrouched) {
        //     animator.SetBool(isCrouchedHash, false);
        // }

        if (Input.GetKeyDown(KeyCode.LeftShift) && (isWalking || z > 0.02f))
        {
            animator.SetBool(isWalkingHash, false);
            animator.SetBool(isCrouchedHash, false);
            animator.SetBool(isRunningHash, true);
            player.setSpeed(runningSpeed);
        }
        else if (Input.GetKeyUp(KeyCode.LeftShift) && isRunning)
        {
            animator.SetBool(isWalkingHash, true);
            animator.SetBool(isRunningHash, false);
            player.setSpeed(walkingSpeed);
        }
        // } else if(PoseParser.GETGestureAsString().CompareTo("N")==0 && isRunning){
        //     animator.SetBool(isWalkingHash, false);
        //     animator.SetBool(isRunningHash, false);
        //     player.setSpeed(walkingSpeed);
        // }

        // if (Input.GetKeyDown(KeyCode.LeftControl) && !isCrouched && !isRunning) {
        //     animator.SetBool(isCrouchedHash, true);
        // } else if (Input.GetKeyDown(KeyCode.LeftControl) && isCrouched) {
        //     animator.SetBool(isCrouchedHash, false);
        // }

        if ((Input.GetButtonDown("Jump") || !isGrounded) && !climbing)
        {
            animator.SetBool(isJumpingHash, true);
            // animator.SetBool(isRunningHash, false);
        }
        else if (isGrounded)
        {
            animator.SetBool(isJumpingHash, false);
        }

        if ((Input.GetKeyDown(KeyCode.LeftControl) || PoseParser.GETGestureAsString().CompareTo("C") == 0) && !crouching && !isRunning)
        {
            crouching = true;
            animator.SetBool(isWalkingHash, false);
            animator.SetBool(isRunningHash, false);
            animator.SetBool(isCrouchedHash, true);
        }
        else if ((Input.GetKeyDown(KeyCode.LeftControl) || PoseParser.GETGestureAsString().CompareTo("N") == 0) && crouching)
        {
            crouching = false;
            // Debug.Log("uncrouch");
            animator.SetBool(isCrouchedHash, false);
            animator.SetBool(isWalkingHash, false);
            animator.SetBool(isRunningHash, false);
        }

        if (z >= 0.02f && crouching)
        {
            animator.SetBool(isCrouchedHash, true);
            animator.SetBool(isWalkingHash, true);
            animator.SetBool(isRunningHash, false);
        }
        else if ((z <= 0.02f && z >= -0.02f) && crouching)
        {
            animator.SetBool(isCrouchedHash, true);
            animator.SetBool(isWalkingHash, false);
            animator.SetBool(isRunningHash, false);
        }
    }
Esempio n. 12
0
    void Update()
    {
        if (!hasAuthority)
        {
            return;
        }

        #if !UNITY_WEBGL || UNITY_EDITOR
        if (Input.GetKeyDown(KeyCode.C))
        {
            character.height = 1.0f;
        }
        else if (Input.GetKeyUp(KeyCode.C))
        {
            character.height = 1.8f;
        }


        if (Input.GetKeyDown(KeyCode.Q))
        {
            characterTransform.Rotate(0, 0, 90, relativeTo: Space.Self);
        }
        else if (Input.GetKeyUp(KeyCode.Q))
        {
            characterTransform.rotation = Quaternion.FromToRotation(characterTransform.up, Vector3.up) * characterTransform.rotation;
        }


        if (Input.GetKeyDown(KeyCode.E))
        {
            characterTransform.Rotate(0, 0, -90, relativeTo: Space.Self);
        }
        else if (Input.GetKeyUp(KeyCode.E))
        {
            characterTransform.rotation = Quaternion.FromToRotation(characterTransform.up, Vector3.up) * characterTransform.rotation;
        }
        #elif UNITY_WEBGL
        if (PoseParser.GETGestureAsString().CompareTo("C") == 0)
        {
            character.height = 1.0f;
        }
        else if (PoseParser.GETGestureAsString().CompareTo("C") != 0)
        {
            character.height = 1.8f;
        }

        if (PoseParser.GETGestureAsString().CompareTo("W") == 0 && !rotated)
        {
            rotated = true;
            characterTransform.Rotate(0, 0, 90, relativeTo: Space.Self);
        }
        else if (PoseParser.GETGestureAsString().CompareTo("Q") == 0 && !rotated)
        {
            rotated = true;
            characterTransform.Rotate(0, 0, -90, relativeTo: Space.Self);
        }
        else if (PoseParser.GETGestureAsString().CompareTo("W") != 0 && PoseParser.GETGestureAsString().CompareTo("Q") != 0)
        {
            rotated = false;
            characterTransform.rotation = Quaternion.FromToRotation(characterTransform.up, Vector3.up) *
                                          characterTransform.rotation;
        }
#endif
    }
Esempio n. 13
0
 public void onClick()
 {
     //Debug.Log("turn off pose");
     PoseParser.turnOffPose();
 }
Esempio n. 14
0
    void Movement()
    {
        // Checks if the groundCheck object is within distance to the ground layer
        bool old = isGrounded;

        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);

        if (old != isGrounded)
        {
            GetComponent <PlayerAnimation>().setGrounded(isGrounded);
        }

        // Prevents downward velocity from decreasing infinitely if player is on the ground
        if (isGrounded && velocity.y < 0)
        {
            velocity.y = -3f;
        }

        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");
        float l = Input.GetAxis("Ladder");

        // instantiates move with null so that it can be set depending on climb
        Vector3 move;

#if UNITY_WEBGL && !UNITY_EDITOR
        if (climbing && PoseParser.GETGestureAsString().CompareTo("L") == 0)
        {
            move = transform.up * 0.2f;
        }
        else if (climbing && l > 0f)
        {
            move = transform.up * l;
        }
        else
        {
            move = transform.right * x + transform.forward * z;
        }
#else
        if (climbing && l > 0f)
        {
            move = transform.up * l;
        }
        else
        {
            move = transform.right * x + transform.forward * z;
        }
#endif

        //Sticks player to centreline of ladder
        if (climbing)
        {
            faceUI.SetActive(false);
            Vector3 ladderPos = train.transform.position + (train.transform.rotation * ladderCentreLine);
            ladderPos.y = transform.position.y;
            move       += ladderPos - transform.position;
        }
        // if forwards velocity is greater than 0 and inside the climbing collider, add to the vertical height instead of the forward height
        else if (climbingBuilding && z > 0f)
        {
            move = transform.right * x + transform.up * z;
        }
        else
        {
            move = transform.right * x + transform.forward * z;
        }

        // sticks the player onto the train
        if (onTrain)
        {
            StartCoroutine(SetFaceActive());
            Debug.Log(GameObject.FindGameObjectWithTag("locomotive"));
            Vector3 trainMove = Vector3.MoveTowards(gameObject.transform.position, GameObject.FindGameObjectWithTag("locomotive").transform.position, Time.deltaTime) - GameObject.FindGameObjectWithTag("locomotive").transform.position;
            trainMove.x = -trainMove.x;
            trainMove.y = 0f;
            trainMove.z = -trainMove.z;
            move       += trainMove;
        }


        controller.Move(move * speed * Time.deltaTime);

        // Checks if jump button is pressed and allows user to jump if they are on the ground
        if (Input.GetButtonDown("Jump") && isGrounded)
        {
            onTrain = false;
            faceUI.SetActive(false);
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
        }

        if (Input.GetKeyDown(KeyCode.LeftControl) && !crouching)
        {
            crouching         = true;
            controller.height = 1.2f;
        }
        else if (Input.GetKeyUp(KeyCode.LeftControl) && crouching)
        {
            crouching         = false;
            controller.height = 1.8f;
        }

        //velocity.y += gravity * Time.deltaTime;
        // Only applies gravity when not climbing, this allows players to stay on ladder
        if (!climbing)
        {
            velocity.y += gravity * Time.deltaTime;
            controller.Move(velocity * Time.deltaTime);
        }
    }