Пример #1
0
    private void FixedUpdate()
    {
        float TimeSpeed = Time.deltaTime * 10f;

        //defenseモード切替
        ballingFlag_prev  = ballingFlag;
        inPlayerFlag_prev = inPlayerFlag;

        if (kb_L3.EnterCheck(defenseDelay <= 0f))
        {
            ballingFlag  = !ballingFlag;
            inPlayerFlag = ballingFlag;
            defenseDelay = 0.3f;

            if (ballingFlag)
            {
                currentPit = PitPoint.search(transform);
            }
            else
            {
                currentPit       = null;
                rb.isKinematic   = false;
                transform.parent = null;
            }
        }
        //inPlayerFlag切り替え
        if (kb_B.EnterCheck(ballingFlag && defenseDelay <= 0f))
        {
            inPlayerFlag = false;
        }


        //プレイヤー制御
        if (EnterInPlayerFlag)
        {
            playerBall.gameObject.SetActive(false);
        }
        if (ExitInPlayerFlag)
        {
            playerBall.Warp();
            playerBall.SetVelocity(rb.velocity);
            playerBall.gameObject.SetActive(true);
            playerBall.transform.position = rb.transform.position;
        }


        //defense状態と通常状態の分岐

        rb.freezeRotation = false;
        rb.velocity       = Vector3.ClampMagnitude(rb.velocity, 15f);
        if (ballingFlag)
        {
            isWarping = false;

            rb.drag        = Mathf.Lerp(rb.drag, 0f, TimeSpeed);
            rb.angularDrag = Mathf.Lerp(rb.angularDrag, 0.3f, TimeSpeed);


            transform.localScale = Vector3.Lerp(transform.localScale, Vector3.one * 0.5f, TimeSpeed);
            gameObject.layer     = LayerMask.NameToLayer("SD");

            if (defenseDelay > 0f)
            {
                //コックピットと共鳴中だったら、玉になる瞬間に引き寄せられる
                if (currentPit)
                {
                    transform.SetPositionAndRotation(Vector3.Lerp(transform.position, currentPit.transform.position + (Vector3.up * 0.5f), Time.deltaTime * 7f), transform.rotation);
                }

                rb.useGravity = false;
                rb.velocity   = Vector3.zero;
                Look(false);

                dilay = 0.5f;
            }
            else
            {
                rb.useGravity = true;

                if (dilay > 0f)
                {
                    dilay -= Time.deltaTime;
                    dilay  = Mathf.Clamp(dilay, 0f, 1f);
                }
                else
                {
                    DefenseMode();
                }
            }
        }
        else
        {
            //ボールから解除される時,爆発する
            //if (ballingFlag_prev)
            //{
            //    Bom.transform.position = transform.position;
            //    Bom.SetActive(true);
            //    Debug.Log("B!!!");
            //    //中身がいれば、垂直にジャンプさせる
            //    if(inPlayerFlag_prev)
            //    {
            //        Vector3 vel = rb.velocity;
            //        vel.y = 15f;
            //        playerBall.ballRB.velocity = vel;
            //    }
            //}

            rb.drag        = Mathf.Lerp(rb.drag, defaultDrag, TimeSpeed);
            rb.angularDrag = Mathf.Lerp(rb.angularDrag, defaultAngularDrag, TimeSpeed);

            transform.localScale = Vector3.Lerp(transform.localScale, Vector3.one * 0.5f, TimeSpeed);
            rb.useGravity        = false;
            DefaultMode();
        }


        prevCollisionFlag = false;

        PitPoint.UD();
    }
Пример #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        //各種判定を確認
        bool isAnyContact = myContacts.IsAnyContact;
        bool isClime      = myContacts.IsWalling;


        ikManager.handFlag_L = false;
        ikManager.handFlag_R = false;

        ikManager.handLookParent_L = tAvatar;
        ikManager.handLookParent_R = tAvatar;

        ikManager.targetHandsWeight -= Time.deltaTime;


        breathingManager.muteFlag = false;



        Transform hip = animator.GetBoneTransform(HumanBodyBones.Hips);


        //各種判定の補正
        //if(isGround)
        //{
        //    upNormal = Vector3.up;
        //}



        //左スティックキー入力
        //        Vector3 InputVel = -KeyManagerHub.main.GetStickVectorFromNormal(true, upNormal, Vector3.Dot(upNormal, Camera.main.transform.up) < 0f);

        Vector3 offsetVector = Vector3.zero;

        //ダッシュ中は早い
        toVector = Vector3.ProjectOnPlane(currentInputVel * states.agi * (dashFlag ? 1.5f : 1f), myContacts.UpNormal_Simple);

        //入力が弱い時は壁走りできない
        //        myContacts.fitFlag = toVector.magnitude > 0.8f;

        //ショット
        Vector3 aimPoint = transform.position + (toVector * 100f);

        Debug.DrawLine(transform.position, aimPoint, Color.blue);
        if (key_R1.EnterCheck(!wireManager.isFuck))
        {
            animator.SetTrigger(animID_AttackTrigger);
            //            wireManager.SearchFuck(transform.position, aimPoint, ballRB);
        }

        if (key_R1.Exit)
        {
            //            wireManager.ResetFuck();
        }

        //隠れる状態の時はしゃがむ
        if (transform.parent)
        {
            if (transform.parent.tag == "Hide" && !isSteping)
            {
                myContacts.setImpact(upNormal * 2.0f);
            }
        }



        //頭が天井にぶつからないように補正
        Ray headRay = new Ray(transform.position, upNormal * 0.5f);

        Debug.DrawRay(headRay.origin, headRay.direction, Color.yellow);

        if (Physics.SphereCast(headRay, ballCollider.radius, out RaycastHit hit, 0.5f, handMask))
        {
            Debug.DrawRay(hit.point, hit.normal, Color.cyan);

            float dDot = Vector3.Dot(upNormal, hit.normal);
            if (dDot < 0f && !isSteping)
            {
                Vector3 down = upNormal * dDot;
                myContacts.setImpact(down * -2.0f);
            }
        }



        //物に触る
        Vector3 handVector = toVector;
        Vector3 lsPos      = animator.GetBoneTransform(HumanBodyBones.LeftShoulder).position;
        Vector3 rsPos      = animator.GetBoneTransform(HumanBodyBones.RightShoulder).position;
        Ray     lsRay      = new Ray(((lsPos - (tAvatar.right * 0.15f)) + (upNormal * 0.1f)) - (tAvatar.forward * 0.1f), tAvatar.forward * 0.5f);
        Ray     rsRay      = new Ray(((rsPos + (tAvatar.right * 0.15f)) + (upNormal * 0.1f)) - (tAvatar.forward * 0.1f), tAvatar.forward * 0.5f);

        //                    float forwardVel = Vector3.Dot(tAvatar.forward, handVector);
        float rayRange  = 1.5f;
        float rayRadius = 0.3f;


        ikManager.handFlag_L = Physics.SphereCast(lsRay, rayRadius, out RaycastHit lsHit, rayRange, handMask);
        ikManager.handFlag_R = Physics.SphereCast(rsRay, rayRadius, out RaycastHit rsHit, rayRange, handMask);

        //体の逆側へ手は伸ばさない

        Vector3 crossVel_L = Vector3.Cross(handVector, lsHit.point - rsRay.origin);
        Vector3 crossVel_R = Vector3.Cross(handVector, rsHit.point - lsRay.origin);

        Debug.DrawRay(lsRay.origin, crossVel_L);
        Debug.DrawRay(rsRay.origin, crossVel_R);

        //if (invLSPos.x > 0.1f) ikManager.handFlag_L = false;
        //if (invRSPos.x < -0.1f) ikManager.handFlag_R = false;
        if (crossVel_L.y > 1f)
        {
            ikManager.handFlag_L = false;
        }
        if (crossVel_R.y < -1f)
        {
            ikManager.handFlag_R = false;
        }

        //
        if (ikManager.handFlag_L)
        {
            ikManager.handLookParent_L = lsHit.transform.transform;

            ikManager.handHit_L = lsHit;


            float tLhandW = Vector3.Dot(-lsHit.normal, handVector);

            ikManager.SetHandTransform(true, lsHit);

            ikManager.targetHandsWeight = tLhandW;
        }
        if (ikManager.handFlag_R)
        {
            ikManager.handLookParent_R = rsHit.transform.transform;

            ikManager.handHit_R = rsHit;

            float tRhandW = Vector3.Dot(-rsHit.normal, handVector);

            ikManager.SetHandTransform(false, rsHit);

            if (ikManager.targetHandsWeight < tRhandW)
            {
                ikManager.targetHandsWeight = tRhandW;
            }
        }

        //if (ikManager.handFlag_L)
        //{
        //    ikManager.handLookParent_L = lsHit.transform.transform;

        //    ikManager.handHit_L = lsHit;
        //    ikManager.SetHandTransform(true, lsHit);


        //    ikManager.targetHandsWeight = 1f;
        //}
        //if (ikManager.handFlag_R)
        //{
        //    ikManager.handLookParent_R = rsHit.transform.transform;
        //    ikManager.handHit_R = rsHit;
        //    ikManager.SetHandTransform(false, rsHit);


        //    ikManager.targetHandsWeight = 1f;
        //}

        ikManager.targetHandsWeight = Mathf.Clamp(ikManager.targetHandsWeight, 0f, 1f);

        //手で触ったものの法線が下だった場合、もしかしたらくぐるかもしれないからちょっとしゃがむ
        Vector3 downVel = lsHit.normal.y < rsHit.normal.y ? lsHit.normal : rsHit.normal;

        if (downVel.y < 0f && !isSteping)
        {
            Vector3 down = Vector3.up * Vector3.Dot(Vector3.down, downVel);
            myContacts.setImpact(down * 0.5f);
        }

        //if (ikManager.handFlag_L || ikManager.handFlag_R)
        //{
        //    toVector -= tAvatar.right * (0.2f * (Vector3.Dot(tAvatar.right, toVector)));//物を押している最中は速度半減
        //}

        //壁登り中は、押し込みモーションを取らない
        //        ikManager.puthWeight = Mathf.Lerp(ikManager.puthWeight, isClime ? 0f : 1f, Time.deltaTime * 3f);

        if (isAnyContact)
        {
            //設地したら、空中ダッシュを回復
            if (isGround)
            {
                restStepCount = states.restStepCount;
                restJumpCount = states.restStepCount;
            }


            //移動
            if (stepCT <= 0f)
            {
                Vector3 fromVector = ballRB.velocity;

                //                if(vel.magnitude > tweakParam.minStickMagnitued)
                //                {
                //                }
                //                else
                //                {
                ////                    offsetVector = Vector3.ProjectOnPlane(-ballRB.velocity , upNormal) * Time.deltaTime*3f;
                //                }
                offsetVector  = toVector - fromVector;
                offsetVector *= offsetVector.magnitude;
                offsetVector  = Vector3.ClampMagnitude(offsetVector, states.agi);
                offsetVector  = Vector3.Lerp(Vector3.zero, offsetVector, Time.deltaTime * currentInputVel.magnitude);

                //ballRB.AddForce(offsetVector, ForceMode.VelocityChange);

                ballRB.AddForceAtPosition(offsetVector, transform.position + upNormal, ForceMode.VelocityChange);
                ballRB.AddForceAtPosition(-offsetVector, transform.position - upNormal, ForceMode.VelocityChange);
            }
        }
        else
        {
            //空中移動
            Vector3 fromVector = ballRB.velocity;

            //                if(vel.magnitude > tweakParam.minStickMagnitued)
            //                {
            //                }
            //                else
            //                {
            ////                    offsetVector = Vector3.ProjectOnPlane(-ballRB.velocity , upNormal) * Time.deltaTime*3f;
            //                }
            offsetVector = toVector - fromVector;
            //                offsetVector *= offsetVector.magnitude;
            offsetVector   = Vector3.Lerp(Vector3.zero, offsetVector, Time.deltaTime);
            offsetVector.y = 0f;
            ballRB.AddForce(offsetVector, ForceMode.VelocityChange);
        }

        //チャクチした瞬間は反動でジャンプできない
        if (myContacts.isNowLanding)
        {
            jumpCT = 0.2f;
        }
        //ジャンプ
        if (key_B.EnterCheck(jumpCT <= 0f && restJumpCount > 0))
        {
            Jump(upNormal, toVector);
        }
        //ステップ
        if (key_L2.EnterCheck(stepCT <= 0f && restStepCount > 0))
        {
            Step(myContacts.UpNormal_Simple, toVector);
        }



        //最後に入力をした際のベクトルを取得

        if (wireManager.isFuck)
        {
            lastInputVel = Vector3.ProjectOnPlane(wireManager.NextFuck.position - transform.position, upNormal);
        }
        //else if (KeyManagerHub.main.GetKey(KeyMode.Stay, Key_Hub.L2) /*CameraManager.main.lookTarget*/)//エイム
        //{
        //    lastInputVel = Vector3.ProjectOnPlane(Camera.main.transform.forward, upNormal);
        //}
        else
        {
            if (isGround || isClime)
            {
                if (currentInputVel.magnitude > tweakParam.minStickMagnitued) //入力があった場合
                {
                    if (ikManager.targetHandsWeight > 0f && !isClime)         //物に触れていた場合
                    {
                        Vector3 normal = Vector3.zero;
                        if (ikManager.handFlag_L && !ikManager.handFlag_R)
                        {
                            normal = ikManager.handHit_L.normal;
                        }
                        else if (ikManager.handFlag_R && !ikManager.handFlag_L)
                        {
                            normal = ikManager.handHit_R.normal;
                        }
                        else
                        {
                            normal = (ikManager.handHit_L.normal + ikManager.handHit_R.normal) * 0.5f;
                        }
                        lastInputVel = Vector3.ProjectOnPlane(Vector3.Lerp(currentInputVel, -normal, ikManager.targetHandsWeight), upNormal);
                    }
                    else//物に触れていなかった場合
                    {
                        //          lastInputVel = ballRB.velocity;
                        lastInputVel = Vector3.ProjectOnPlane(currentInputVel, upNormal);
                    }
                }
                else//なかった場合
                {
                    lastInputVel = Vector3.ProjectOnPlane(tAvatar.forward, upNormal);
                }
            }
            else
            {
                lastInputVel = Vector3.ProjectOnPlane(ballRB.velocity, upNormal);
            }
        }
    }