Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        //defense移行の時間制御
        defenseDelay -= Time.deltaTime;
        defenseDelay  = Mathf.Clamp(defenseDelay, 0f, 1f);



        if (KeyManagerHub.main.GetKey(KeyMode.Enter, Key_Hub.L3))
        {
            kb_L3.SetEnter();
        }
        //設置切り替え
        if (KeyManagerHub.main.GetKey(KeyMode.Enter, Key_Hub.X))
        {
            stayFlag = !stayFlag;
            stayPos  = transform.position;
        }
        //defenseの中身からっぽ切り替え
        if (KeyManagerHub.main.GetKey(KeyMode.Enter, Key_Hub.B))
        {
            kb_B.SetEnter();
        }



        //アニメーターセット
        animator.SetBool(AnmID_Defense, ballingFlag);
        animator.SetBool(AnmID_isAnimated, defenseDelay > 0f);

        //defense移行エフェクトセット
        if (ballingFlag && defenseDelay > 0f)
        {
            ve.Play();
        }
        else
        {
            ve.Stop();
        }



        //ボールウェイト
        float weightSpeed = 15f;

        darkColorWeight += inPlayerFlag ? Time.deltaTime * weightSpeed : -Time.deltaTime * weightSpeed;
        darkColorWeight  = Mathf.Clamp(darkColorWeight, -5f, 5f);


        //でぃそるぶとボール闇落ちカラー変更
        warpWeight += isWarping ? Time.deltaTime : -Time.deltaTime;
        warpWeight  = Mathf.Clamp(warpWeight, 0f, 1f);


        var mpb = new MaterialPropertyBlock();

        mpb.SetFloat(sid_Dissolve, ((warpWeight - 0.5f) * -2f));
        mpb.SetFloat(sid_Ball_Weight, darkColorWeight);
//        mpb.SetColor(sid_BaseColor, emitColor);
        foreach (Renderer r in renderers)
        {
            r.SetPropertyBlock(mpb);
        }
    }
Exemplo n.º 2
0
    private void Update()
    {
        bool isAnyContact = myContacts.IsAnyContact;
        bool isWalling    = myContacts.IsWalling;

        stepCT -= Time.deltaTime;
        jumpCT -= Time.deltaTime;
        stepCT  = Mathf.Clamp(stepCT, 0f, 1f);
        jumpCT  = Mathf.Clamp(jumpCT, 0f, 1f);

        //左スティックキー入力
        currentInputVel = -KeyManagerHub.main.GetStickVectorFromNormal(true, myContacts.UpNormal_Simple, false /*Vector3.Dot(upNormal, Camera.main.transform.up) < 0f*/);
        if (!isAerial)
        {
//            currentInputVel *= myContacts.FitWeight;
        }
        if (currentInputVel.magnitude <= 0f && isGround)
        {
            freezWeight += Time.deltaTime * 5f;
        }
        else
        {
            freezWeight -= Time.deltaTime * 5f;
        }
        freezWeight = Mathf.Clamp(freezWeight, 0f, 1f);
        if (stepCT <= 0f)
        {
            if (freezWeight >= 1f)
            {
                ballRB.freezeRotation = true;
            }
            else
            {
                ballRB.freezeRotation  = false;
                ballRB.angularVelocity = Vector3.Lerp(ballRB.angularVelocity, Vector3.zero, Time.deltaTime * freezWeight * 30f);
            }
        }
        //        InputVel = Vector3.Lerp(InputVel ,  Vector3.zero , myContacts.Impact.magnitude*3f);

        if (KeyManagerHub.main.GetKey(KeyMode.Enter, Key_Hub.B))
        {
            key_B.SetEnter();
        }

        if (KeyManagerHub.main.GetKey(KeyMode.Enter, Key_Hub.L2))
        {
            key_L2.SetEnter();
        }
        dashFlag = KeyManagerHub.main.GetKey(KeyMode.Stay, Key_Hub.L2);

        if (KeyManagerHub.main.GetKey(KeyMode.Enter, Key_Hub.R1))
        {
            key_R1.SetEnter();
        }
        if (KeyManagerHub.main.GetKey(KeyMode.Exit, Key_Hub.R1))
        {
            key_R1.SetExit();
        }


        //float timeChangeSpeed = Time.unscaledDeltaTime * 3f;
        //timeScale += KeyManagerHub.main.GetKey(KeyMode.Stay, Key_Hub.R2) ? -timeChangeSpeed : timeChangeSpeed;
        //timeScale = Mathf.Clamp(timeScale, 0f, 1f);
        //Time.timeScale = Mathf.Lerp(0.3f, 1f, timeScale);//(currentInputVel.magnitude*0.5f);
        if (KeyManagerHub.main.GetKey(KeyMode.Stay, Key_Hub.R2))
        {
            Time.timeScale = 0.5f;
        }
        else
        {
            Time.timeScale = 1f;
        }



        //回転方向と現在方向の差
        Vector3 uN = myContacts.upNormal_Ex;

        //        float angle = Vector3.Angle(uN, animator.transform.up) * 0.05f;

        //人体座標をボール座標と重ねる
        if (!tAvatar.gameObject.activeSelf)
        {
            return;
        }
        Vector3 uNor = Vector3.Lerp(tAvatar.up, upNormal, Time.deltaTime).normalized;

        float ofsH = 0.05f;

        tAvatar.position     = transform.position - (uNor * (ballCollider.radius + ofsH));
        ikManager.currentPos = transform.position - (uNor * (ballCollider.radius + ofsH));
        //人体座標を、衝撃ぶんずらす
        Vector3 impVel = myContacts.Impact;

        impVel = Vector3.ClampMagnitude(impVel, 0.75f);
        //横軸強すぎると顔面壁にぶつかる
        float downDot = Vector3.Dot(upNormal, impVel);

        //ステップ中じゃなければ、空中じゃなければ足のIK補正でしゃがむ、衝撃でしゃがむ
        if (!isAerial && !isSteping)
        {
            downDot = Mathf.Max(downDot, ikManager.HOfs);
        }
        impVel           += upNormal * downDot;
        impVel           *= 0.5f;
        tAvatar.position -= impVel;

        //アバターの方向転換
        tAvatar.parent = transform.parent;

        Vector3 liv = lastInputVel;


        if (uN != Vector3.up)
        {
            Vector3 axis = Vector3.Cross(Vector3.up, uN);

            //坂道に立っている時の姿勢補正
            float tiltDot = Mathf.Abs(Vector3.Dot(Vector3.up, upNormal)) - 1f;
            if (!isSteping)
            {
                myContacts.setImpact(upNormal * Mathf.Clamp(tiltDot * -1.5f, 0f, 1.5f));
                Quaternion wallQ = Quaternion.AngleAxis(-45f * -tiltDot, axis);
                uN = wallQ * uN;
            }
        }
        Debug.DrawRay(transform.position, uN, Color.red);

        tAvatar.rotation = Quaternion.Lerp(tAvatar.rotation, Quaternion.LookRotation(liv, uN), (tweakParam.avaterRotationSpeed /*+ angle*/) * Time.deltaTime);

        //ステップ中はしゃがまない
        if (isSteping)
        {
            myContacts.DragImpact();
        }

        //IKマネージャーの壁登りフラグを立てる
        //        ikManager.climeFlag = isClime;


        //回転する時は体を丸める
        Vector3 upOfs = upNormal - tAvatar.up;

        //アニメーション更新
        animator.SetLayerWeight(animLayer_impact, (downDot * 4f) + (upOfs.magnitude));


        //非操作時間とそれによるアイドル変化
        if (/*ballRB.velocity.sqrMagnitude*/ currentInputVel.sqrMagnitude < 0.01f)
        {
            nonOperatingTime += Time.deltaTime;

            lookRotation.rotation = Quaternion.Lerp(lookRotation.rotation, Camera.main.transform.rotation, Time.deltaTime * 5f);


            if (nonOperatingTime > tweakParam.specialIdleTime)
            {
                ikManager.nextLookTarget = Camera.main.transform;
            }
        }
        else
        {
            //if (isGround)
            //{
            if (toVector.sqrMagnitude <= 0f)
            {
                toVector = tAvatar.forward;
            }

            Transform head = animator.GetBoneTransform(HumanBodyBones.Head);
            lookRotation.position = head.position;

            float      upVelDot  = Vector3.Dot(animator.transform.up, ballRB.velocity) * 0.5f;
            Vector3    lookUpOfs = animator.transform.up * upVelDot;
            Quaternion toRad     = Quaternion.LookRotation(toVector + lookUpOfs, Vector3.up);;
            Quaternion fromRad   = lookRotation.rotation;


            lookRotation.rotation = Quaternion.Lerp(fromRad, toRad, Time.deltaTime * 5f);



            Debug.DrawRay(transform.position, lookRotation.forward, Color.yellow);

            ikManager.nextLookTarget = lookForward;
            //}
            //else
            //{
            //    ikManager.nextLookTarget = null;
            //}

            nonOperatingTime = 0f;
        }


        float animationSpeed = Time.deltaTime * 30f;


        //空中判定
        if (!myContacts.IsAnyContact)
        {
            aerialTimer -= Time.deltaTime;
            aerialTimer  = Mathf.Clamp(aerialTimer, 0f, 1f);
        }
        else
        {
            aerialTimer = 0.1f;
        }

        animator.SetBool(animID_isAerial, isAerial);
        //空中ベクトル変化は、空中時のみ変化(チャクチした瞬間等、変化が激しすぎてアニメーションが一瞬で切り替わる)
        ikManager.isAerial = isAerial;
        if (isAerial)
        {
            //空中だった場合ステップアニメはCancel
            animator.ResetTrigger(animID_stepTrigger);
            //空中でステップ中だった場合重力なし,アニメーション重力も上昇に固定
            float zone = 5f;
            float yVel = Mathf.Clamp((animator.transform.InverseTransformVector(myContacts.LastPhysicsVector).y + zone) / (zone * 2f), 0f, 1f);
            yVel = Mathf.Lerp(1f, 0f, yVel);
            yVel = Mathf.Lerp(animator.GetFloat(animID_speed_Y), yVel, Time.deltaTime * 60f);

            ballRB.useGravity = true;


            animator.SetFloat(animID_speed_Y, Mathf.Lerp(animator.GetFloat(animID_speed_Y), yVel, animationSpeed));


            //移動アニメーション空中
            Vector3 animatedVector = ballRB.velocity;
            animatedVector   = tAvatar.InverseTransformVector(animatedVector);
            animatedVector.y = 0f;
            float speed_Z = animatedVector.z;
            float speed_X = animatedVector.x;


            animator.SetFloat(animID_speed_X, Mathf.Lerp(animator.GetFloat(animID_speed_X), speed_X, animationSpeed));
            animator.SetFloat(animID_speed_Z, Mathf.Lerp(animator.GetFloat(animID_speed_Z), speed_Z, animationSpeed));
            animator.SetFloat(animID_speed, 1f);
        }
        else
        {
            //移動アニメーション地上
            Vector3 animatedVector = ballRB.angularVelocity * 0.5f;
            animatedVector   = tAvatar.InverseTransformVector(animatedVector);
            animatedVector.y = 0f;
            float speed_Z = animatedVector.x;
            float speed_X = -animatedVector.z;


            animator.SetFloat(animID_speed_X, Mathf.Lerp(animator.GetFloat(animID_speed_X), speed_X, animationSpeed));
            animator.SetFloat(animID_speed_Z, Mathf.Lerp(animator.GetFloat(animID_speed_Z), speed_Z, animationSpeed));
            animator.SetFloat(animID_speed, Mathf.Lerp(animator.GetFloat(animID_speed), animatedVector.magnitude * 0.5f, animationSpeed));
        }

        //        playerAnimator.SetBool(animID_isWalling, isClime);

        //息遣い
        if (isAerial)
        {
            breathingManager.Fatigue(ballRB.velocity.magnitude);
        }
    }