Пример #1
0
    // Update is called once per frame
    private void FixedUpdate()
    {
        Vector3 moveVector = Vector3.zero;

        if (moveState == MOVE_STATE.GRAPPLING_HOOK)
        {
            Vector3 moveDir = grappleHookTarget - transform.position;

            //Vector3 finalMoveDir = Vector3.ClampMagnitude(moveDir, grapplingHookSpeed);
            Vector3 finalMoveDir = moveDir.normalized * grapplingHookSpeed;

            moveVector += finalMoveDir;
        }
        else
        {
            if (moveState == MOVE_STATE.JUMPING)
            {
                if (timeSinceJumpStart < jumpDuration)
                {
                    timeSinceJumpStart += Time.deltaTime;
                    moveVector         += Vector3.up * jumpHeight * (jumpDuration - timeSinceJumpStart);
                }
                else if (charController.isGrounded)
                {
                    moveState = MOVE_STATE.ON_GROUND;
                }
            }


            Vector3 nonJumpMovement = Vector3.zero;

            for (int move = 0; move < momentVectors.Length; ++move)
            {
                nonJumpMovement += momentVectors[move] * moveSpeed;
            }

            nonJumpMovement.y = 0;

            moveVector += nonJumpMovement;

            moveVector += Physics.gravity;
        }


        MoveChar(moveVector);

        if (moveVector != Vector3.zero)
        {
            // Send data to the Server
            fpsPlayer.SetPlayerPosn(transform.position);
        }

        for (int move = 0; move < momentVectors.Length; ++move)
        {
            momentVectors[move] = Vector3.zero;
        }
    }