示例#1
0
    void FixedUpdate()
    {
        if (deltaPosition != Vector3.zero)
        {
            PlayerAnimationController.SetBool("IsRunning", true);

            horizontalVelocity += MovementSpeed * pickingUpSpeedPercentage;
            if (horizontalVelocity > MovementSpeed)
            {
                horizontalVelocity = MovementSpeed;
            }

            if (PlayerAnimationController.GetBool("IsRunning") &&
                !PlayerAnimationController.Animator.GetCurrentAnimatorStateInfo(0).IsName("Run") &&
                !PlayerAnimationController.Animator.GetCurrentAnimatorStateInfo(0).IsName("Turn") &&
                !PlayerAnimationController.GetBool("IsAttacking") &&
                !PlayerAnimationController.GetBool("IsJumping"))
            {
                PlayerAnimationController.CrossfadeAnimation("Walk-Run", 0.01f);
            }

            if (PlayerAnimationController.GetBool("IsAttacking"))
            {
                horizontalVelocity *= slowPercentageWhenAttacking;
            }

            transform.LookAt(transform.position + deltaPosition);
            transform.Rotate(Vector3.up * 90f);
            transform.position += (deltaPosition * horizontalVelocity) * Time.fixedDeltaTime / 20;

            //Vector3 vel = rb.velocity;
            //print(deltaPosition * horizontalVelocity);
            //rb.MovePosition(Vector3.SmoothDamp(transform.position, transform.position + deltaPosition * horizontalVelocity, ref vel, 1f));

            //rb.MovePosition(transform.forward * horizontalVelocity);
        }
        else
        {
            horizontalVelocity = 0;
        }


        PlayerAnimationController.SetFloat("Velocity", horizontalVelocity / 150f);
    }
示例#2
0
    void Update()
    {
        if (Input.GetKeyDown(jumpKey) && !hasDoubleJumped)
        {
            if (isJumping)
            {
                rb.velocity     = Vector3.zero;
                hasDoubleJumped = true;
            }
            else
            {
                isJumping = true;
            }

            if (!PlayerAnimationController.GetBool("IsAttacking"))
            {
                PlayerAnimationController.CrossfadeAnimation("Jump", 0.15f);
            }

            PlayerAnimationController.SetBool("IsJumping", true);
            rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
            InvokeRepeating("ResetJump", 1f, 0.1f);
            StartCoroutine("ReadyToLand");
        }

        if ((Input.GetKeyUp(moveRightKey) && !Input.GetKey(moveLeftKey)) || (Input.GetKeyUp(moveLeftKey) && !Input.GetKey(moveRightKey)))
        {
            PlayerAnimationController.SetBool("IsRunning", false);
            if (!PlayerAnimationController.GetBool("IsAttacking") && !PlayerAnimationController.GetBool("IsJumping"))
            {
                PlayerAnimationController.Animator.Play("Idle");
            }
        }

        RaycastHit groundHit;

        if (Physics.Raycast(transform.position + Vector3.up * transform.localScale.y, Vector3.down, out groundHit, groundLayerMask))
        {
            if (isReadyToLand && Vector3.Distance(transform.position, groundHit.point) <= 1f)
            {
                if (!PlayerAnimationController.GetBool("IsAttacking"))
                {
                    PlayerAnimationController.CrossfadeAnimation("Jump_land", 0.15f);
                }
                PlayerAnimationController.SetBool("IsJumping", false);
                isReadyToLand = false;
            }

            if (Vector3.Distance(transform.position, groundHit.point) >= 2f)
            {
                if (!PlayerAnimationController.GetBool("IsAttacking"))
                {
                    PlayerAnimationController.CrossfadeAnimation("Jump_air", 0.1f);
                }
                PlayerAnimationController.SetBool("IsJumping", true);
                isReadyToLand = true;
            }
        }

        deltaPosition = Vector3.zero;

        if (Input.GetKey(moveLeftKey))
        {
            deltaPosition.z = 1;

/*            if (Rotation != -1)
 *          {
 *              Rotation = -1;
 *              transform.Rotate(0, 180, 0);
 *              if (!PlayerAnimationController.GetBool("IsAttacking"))
 *                  PlayerAnimationController.PlayAnimation("Turn");
 *          }*/
        }
        else if (Input.GetKey(moveRightKey))
        {
            deltaPosition.z = -1;

            /*
             * if (Rotation != 1)
             * {
             *  Rotation = 1;
             *  transform.Rotate(0, 180, 0);
             *  if (!PlayerAnimationController.GetBool("IsAttacking"))
             *      PlayerAnimationController.PlayAnimation("Turn");
             * }*/
        }

        if (Input.GetKey(moveForwardKey))
        {
            deltaPosition.x = 1;
        }
        else if (Input.GetKey(moveBackKey))
        {
            deltaPosition.x = -1;
        }
    }