Esempio n. 1
0
    private void PlayerMove()
    {
        if (autorun && InputParams.zAxis >= 0)
        {
            InputParams.zAxis = 1;
        }

        if (InputParams.xAxis != 0f || InputParams.zAxis != 0f)// при ненулевых значения хотябы одной из осей
        {
            anim.SetRunSpeed(Mathf.Abs(InputParams.xAxis));
            RotVector.Set(InputParams.xAxis, 0f, InputParams.zAxis);

            float vmax = Time.fixedDeltaTime * MoveForce * MoveForceKoef;

            //поворот+

            Vector3 RotProjection = Vector3.ProjectOnPlane(RotVector, transform.up);
            float   angleTurnY;
            if (MoveType == MoveTypeEnum.Worldspace)
            {
                angleTurnY = Vector3.SignedAngle(transform.forward, RotProjection, transform.up);
                transform.Rotate(0f, angleTurnY * RotateCoef * Time.fixedDeltaTime, 0f, Space.Self);
            }
            else if (MoveType == MoveTypeEnum.LocalTurn)
            {
                //BodyTrigers.isFall == false
                if (true)
                {
                    transform.Rotate(0f, InputParams.xAxis * RotateCoef * Time.fixedDeltaTime, 0f, Space.Self);
                }
            }


            //поворот-
            //BodyTrigers.isOnGround && !BodyTrigers.isJump && !BodyTrigers.isFall
            if (true)
            {
                anim.Run(true);
                if ((CanMove))
                {
                    if (MoveType == MoveTypeEnum.Worldspace)
                    {
                        float curMaxV = getDivCoefWithMaxLimit(vmax, InputParams.xAxis, InputParams.zAxis);
                        rb.velocity = new Vector3(RotProjection.x * curMaxV, rb.velocity.y, RotProjection.z * curMaxV);
                    }
                    else if (MoveType == MoveTypeEnum.LocalTurn)
                    {
                        Vector3 down    = Vector3.Project(rb.velocity, transform.up);
                        Vector3 forward = transform.forward * InputParams.zAxis * vmax;
                        rb.velocity = down + forward;
                    }
                }
            }


            else if (BodyTrigers.isFall)
            {
                if (MoveType == MoveTypeEnum.Worldspace)
                {
                    rb.AddForce(RotVector * Time.fixedDeltaTime * FallMoveForce, ForceMode.VelocityChange);
                }
                else if (MoveType == MoveTypeEnum.LocalTurn)
                {
                    float   curMaxV = getDivCoefWithMaxLimit(FallMoveForce, InputParams.xAxis, InputParams.zAxis);
                    Vector3 down    = Vector3.Project(rb.velocity, transform.up);
                    Vector3 forward = transform.forward * InputParams.zAxis * curMaxV;
                    Vector3 right   = transform.right * InputParams.xAxis * curMaxV;
                    rb.velocity = right + down + forward;
                }
                anim.Run(false);
            }
        }
        else
        {
            anim.Run(false);
        }

        if (InputParams.jumpButton && Vector3.Distance(transform.position, Vector3.zero) <= maxHight)
        {
            soundControl.Jump();
            //InputParams.jumpButton = false;

            StartCoroutine(JumpAfterDelay(JumpDelayBefore, true));
        }
    }