Exemple #1
0
    /////////////////////////////////////////////////////////////////
    // Updates gameplay and physics
    /////////////////////////////////////////////////////////////////
    private void FixedUpdate()
    {
        if (obstacle != null)
        {
            Debug.DrawLine(playerObject.transform.position, hitPoint, debugColour, 0.01f);

            // Set hit point
            hitPoint = obstacle.GetComponent <Collider>().ClosestPoint(playerObject.transform.position);

            if (playerScript.GetMovementState() == MovementState.CLIMBING)
            {
                // Mantle after climbing
                if (playerObject.transform.position.y >= (GetTopEdge(obstacle).y - playerScript.GetCrouchHeight()) &&
                    playerObject.transform.position.y <= GetTopEdge(obstacle).y)
                {
                    playerScript.SetMovementState(MovementState.MANTLING);
                }
                // Face obstacle while climbing
                else
                {
                    playerObject.transform.LookAt(hitPoint);
                }
            }

            // Measure obstacle dimensions
            ObstacleCheck(obstacle);

            // Set action point if action started
            if (playerScript.ActionStarted())
            {
                // Face obstacle
                Vector3 lookPos = hitPoint - playerObject.transform.position;
                lookPos.y = 0.0f;
                playerObject.transform.rotation = Quaternion.LookRotation(lookPos);

                // Set points to move towards
                SetActionPoints();
            }
        }
    }
Exemple #2
0
    /////////////////////////////////////////////////////////////////
    // Takes player input
    /////////////////////////////////////////////////////////////////
    public void PlayerInput()
    {
        // EXIT
        if (Input.GetButtonDown("Exit"))
        {
            Application.Quit();
        }

        // CAMERA

        if (Input.GetAxis("Mouse X") != 0.0f ||
            Input.GetAxis("Mouse Y") != 0.0f)
        {
            MoveCamera(Input.GetAxis("Mouse X"),
                       Input.GetAxis("Mouse Y"));
        }

        // MOVEMENT

        switch (playerScript.GetMovementState())
        {
        case MovementState.STANDING:

            // Player falls
            if (!playerScript.CanJump())
            {
                playerScript.SetMovementState(MovementState.FALLING);
            }

            // Player crouchs
            else if (Input.GetButtonDown("Crouch"))
            {
                playerScript.SetMovementState(MovementState.CROUCHING);
            }

            // If player inputs movement
            else if (Input.GetAxis("Horizontal") != 0.0f ||
                     Input.GetAxis("Vertical") != 0.0f)
            {
                playerScript.SetMovementState(MovementState.WALKING);
            }

            // Player jumps
            else if (Input.GetButtonDown("Jump"))
            {
                playerScript.Jump();
            }
            break;

        case MovementState.CROUCHING:

            // Player falls
            if (!playerScript.CanJump())
            {
                playerScript.SetMovementState(MovementState.FALLING);
            }

            // Player stands up
            else if (Input.GetButtonDown("Crouch"))
            {
                playerScript.SetMovementState(MovementState.STANDING);
            }

            // If player inputs movement
            else if (Input.GetAxis("Horizontal") != 0.0f ||
                     Input.GetAxis("Vertical") != 0.0f)
            {
                playerScript.SetMovementState(MovementState.SNEAKING);
            }
            break;

        case MovementState.SNEAKING:

            // Player falls
            if (!playerScript.CanJump())
            {
                playerScript.SetMovementState(MovementState.FALLING);
            }

            // Player stands up
            else if (Input.GetButtonDown("Crouch"))
            {
                playerScript.SetMovementState(MovementState.WALKING);
            }

            // Player stops moving
            else if (Input.GetAxis("Horizontal") == 0.0f &&
                     Input.GetAxis("Vertical") == 0.0f)
            {
                playerScript.SetMovementState(MovementState.CROUCHING);
            }

            // Player moves
            else
            {
                playerScript.Move(Input.GetAxis("Horizontal"),
                                  Input.GetAxis("Vertical"));
            }
            break;

        case MovementState.WALKING:

            // Player falls
            if (!playerScript.CanJump())
            {
                playerScript.SetMovementState(MovementState.FALLING);
            }

            // Player crouchs
            else if (Input.GetButtonDown("Crouch"))
            {
                playerScript.SetMovementState(MovementState.SNEAKING);
            }

            // Player jumps
            else if (Input.GetButtonDown("Jump"))
            {
                playerScript.Jump();
            }

            // Player runs
            else if (Input.GetButton("Sprint") ||
                     Input.GetAxis("Sprint") == 1)
            {
                playerScript.SetMovementState(MovementState.RUNNING);
            }

            // Player stops moving
            else if (Input.GetAxis("Horizontal") == 0.0f &&
                     Input.GetAxis("Vertical") == 0.0f)
            {
                playerScript.SetMovementState(MovementState.STANDING);
            }

            // Player moves
            else
            {
                playerScript.Move(Input.GetAxis("Horizontal"),
                                  Input.GetAxis("Vertical"));
            }
            break;

        case MovementState.RUNNING:

            // Player falls
            if (!playerScript.CanJump())
            {
                playerScript.SetMovementState(MovementState.FALLING);
            }

            // Player slides
            else if (Input.GetButton("Crouch") &&
                     playerScript.CanSlide())
            {
                playerScript.SetMovementState(MovementState.SLIDING);
            }

            // Player jumps
            else if (Input.GetButtonDown("Jump"))
            {
                playerScript.Jump();
            }

            // Player runs
            else if (!Input.GetButton("Sprint") &&
                     Input.GetAxis("Sprint") != 1)
            {
                playerScript.SetMovementState(MovementState.WALKING);
            }

            // Player stops moving
            else if (Input.GetAxis("Horizontal") == 0.0f &&
                     Input.GetAxis("Vertical") == 0.0f)
            {
                playerScript.SetMovementState(MovementState.STANDING);
            }

            // Player moves
            else
            {
                playerScript.Move(Input.GetAxis("Horizontal"),
                                  Input.GetAxis("Vertical"));
            }
            break;

        case MovementState.JUMPING:
        case MovementState.FALLING:

            // Player lands
            if (playerScript.CanJump())
            {
                playerScript.SetMovementState(MovementState.STANDING);
            }

            // If player inputs movement
            if (Input.GetAxis("Horizontal") != 0.0f ||
                Input.GetAxis("Vertical") != 0.0f)
            {
                // Pass input axis into move function
                playerScript.Move(Input.GetAxis("Horizontal"),
                                  Input.GetAxis("Vertical"));
            }
            break;

        case MovementState.CLIMBING:
            if (playerScript.GetStatePhase() == StatePhase.END)
            {
                // Player on ground
                if (playerScript.CanJump())
                {
                    playerScript.SetMovementState(MovementState.STANDING);
                }

                // Player jumps
                else if (Input.GetButtonDown("Jump"))
                {
                    playerScript.Jump();
                }

                // Player moves
                else
                {
                    playerScript.Move(Input.GetAxis("Horizontal"),
                                      Input.GetAxis("Vertical"));
                }
            }
            break;

        default:
            break;
        }

        // FOR TESTING PURPOSES ONLY!

        if (Input.GetKeyDown("1"))
        {
            playerScript.SetMovementState(MovementState.VAULTING);
        }

        if (Input.GetKeyDown("2"))
        {
            playerScript.SetMovementState(MovementState.SLIDING);
        }

        if (Input.GetKeyDown("3"))
        {
            playerScript.SetMovementState(MovementState.MANTLING);
        }

        if (Input.GetKeyDown("4"))
        {
            playerScript.SetMovementState(MovementState.CLIMBING);
        }
    }