Пример #1
0
    /// <summary>
    /// прыжок с задержко перед ним
    /// </summary>
    /// <param name="delay">время задержки</param>
    /// /// <param name="stopBeforeJump">притормаживать перед прыжком</param>
    /// <returns></returns>
    private IEnumerator JumpAfterDelay(float delay, bool stopBeforeJump = false)
    {
        //BodyTrigers.CanJump()
        if (true)
        {
            BodyTrigers.isJump = true;

            if (stopBeforeJump)
            {
                StartCoroutine(DragAfterLanding(rb, DragAfterLand, (delay / 2)));
            }

            anim.Jump();


            BodyTrigers.isOnGround = false;
            yield return(new WaitForSeconds(delay));


            float koef    = 1;
            float divKoef = Mathf.Abs(InputParams.xAxis) + Mathf.Abs(InputParams.zAxis);
            if (divKoef != 0)
            {
                koef = JumpLengthForce / divKoef;
            }
            float addJumpForce = 0f;
            if (transform.parent)
            {
                TransformSpeed trSpeed = transform.parent.GetComponent <TransformSpeed>();
                if (trSpeed)
                {
                    addJumpForce = trSpeed.velocityTransform.y / 2;
                }
            }

            if (MoveType == MoveTypeEnum.Worldspace)
            {
                rb.velocity = new Vector3(InputParams.xAxis * koef, JumpUpForce + addJumpForce, InputParams.zAxis * koef);
            }
            else if (MoveType == MoveTypeEnum.LocalTurn)
            {
                rb.AddForce(transform.up * JumpUpForce);
            }
        }

        BodyTrigers.isJump = false;
        BodyTrigers.isFall = true;
    }