Beispiel #1
0
    public void MoveInDirection(Direction direction)
    {
        switch (direction)
        {
        case Direction.Up:
            rBody.velocity = transform.up * flySpeed;;
            break;

        case Direction.Down:
            rBody.velocity = -1 * transform.up * flySpeed;
            break;

        case Direction.Forward:
            rBody.velocity = transform.forward * flySpeed;
            break;

        case Direction.Backward:
            rBody.velocity = -1 * transform.forward * flySpeed;
            break;

        case Direction.Right:
            rBody.velocity = transform.right * flySpeed;
            break;

        case Direction.Left:
            rBody.velocity = -1 * transform.right * flySpeed;
            break;
        }

        pTransform.SetSynchronizedValues(rBody.velocity, 0);
    }
    public void Update()
    {
        if (!pView.IsMine || !characterController)
        {
            return;
        }

        pTransform.SetSynchronizedValues(characterController.velocity, 0);

        if (isUsingOffensive)
        {
            if (characterAnimator.GetFloat("VelFwd") != 0 || characterAnimator.GetFloat("VelRight") != 0)
            {
                //pTransform.SetSynchronizedValues(new Vector3(0 ,0 ,0), 0);
                pView.RPC("RPC_StopOnOccupyingOffensive", RpcTarget.All);
            }
            return;
        }

        if (Input.GetButtonDown("Run") && !isDashing && (Input.GetAxis("Vertical") > 0))
        {
            DashPls();
        }

        if (Input.GetButtonUp("Run"))
        {
            StopDashingPls();
        }


        axisVertical   = Input.GetAxis("Vertical");
        axisHorizontal = Input.GetAxis("Horizontal");

        #region Grounded Check
        if (Physics.Raycast(transform.position, -1 * transform.up, 0.02f))//0.005
        {
            isGrounded = true;
            if (!canWallJump)
            {
                canWallJump = true;
            }
        }
        else //if(isGrounded)
        {
            isGrounded = false;
        }
        #endregion

        if (isGrounded)
        {
            if (playerInAir)
            {
                playerInAir = false;
                pView.RPC("RPC_PlayAnimationOnClients", RpcTarget.All, "PlayerLanded");
            }
            moveDirection = currentSpeed * ((transform.forward * axisVertical) + (transform.right * strafeSpeedMultiplier * axisHorizontal));

            if (Input.GetButtonDown("Jump"))
            {
                if (Vector3.Magnitude(characterController.velocity) < jumpRunThreshold)
                {
                    pView.RPC("RPC_PlayAnimationOnClients", RpcTarget.All, "StandingJump");
                }
                else
                {
                    pView.RPC("RPC_PlayAnimationOnClients", RpcTarget.All, "RunningJump");
                }
                playerInAir     = true;
                moveDirection.y = jumpSpeed;
            }
        }

        else if (Input.GetButtonDown("Jump") && isWallGliding && canWallJump)
        {
            canWallJump   = false;
            moveDirection = 30 * playerCam.transform.forward;
            //moveDirection += 7.5f * transform.up;
        }

        moveDirection.y -= gravity * Time.deltaTime;

        characterController.Move(moveDirection * Time.deltaTime);

        //pTransform.SetSynchronizedValues(characterController.velocity, 0);

        characterAnimator.SetFloat("VelRight", axisHorizontal);
        characterAnimator.SetFloat("VelFwd", axisVertical * (Input.GetButton("Run") ? 1 : 0.5f));
    }