Exemplo n.º 1
0
        void FixedUpdate()
        {
#if UNITY_EDITOR
            if (!isDebugMovable)
            {
#endif
            if (!StageManager.CanMove)
            {
                return;
            }
#if UNITY_EDITOR
        }
#endif

            stellaActionScriptableObjects[(int)NowAction]?.UpdateAction();

            if (ChrController.collisionFlags.HasFlag(CollisionFlags.Below))
            {
                // 下判定があったら、埋まっていないか確認
                int   cnt    = PhysicsCaster.CharacterControllerCast(ChrController, Vector3.down, 0f, PhysicsCaster.MapCollisionLayer);
                float checkY = ChrController.bounds.min.y + walkDownY;
                for (int i = 0; i < cnt; i++)
                {
                    ColliderIgnore[] ci = PhysicsCaster.hits[i].collider.GetComponents <ColliderIgnore>();
                    // 足元より上なら無効化
                    for (int j = 0; j < ci.Length; j++)
                    {
                        if (ci[j].Top > checkY)
                        {
                            ci[j].Sleep();
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 移動先のチェックを行ってPushActionを呼び出します。
        /// また、岩にめり込む対策のため、移動方向で埋まっていたら、埋まらない場所まで戻します。
        /// </summary>
        /// <returns>戻す処理をしていたらtrueを返します。</returns>
        protected bool PushCheck()
        {
            float h        = StellaMove.ChrController.height * 0.5f - StellaMove.ChrController.radius;
            int   hitCount = PhysicsCaster.CharacterControllerCast(
                StellaMove.ChrController,
                StellaMove.forwardVector,
                Mathf.Abs(StellaMove.myVelocity.x * Time.fixedDeltaTime),
                PhysicsCaster.MapCollisionLayer);
            bool isBack = false;

            for (int i = 0; i < hitCount; i++)
            {
                Actable[] acts = PhysicsCaster.hits[i].collider.GetComponents <Actable>();
                for (int j = 0; j < acts.Length; j++)
                {
                    if (!acts[j].CanAction)
                    {
                        continue;
                    }

                    // 方向が左右か
                    float ydif      = PhysicsCaster.hits[i].point.y - StellaMove.ChrController.bounds.center.y;
                    float sidecheck = h + StellaMove.ChrController.radius * 0.5f;
                    if (Mathf.Abs(ydif) > sidecheck)
                    {
                        continue;
                    }

                    // 移動していて、移動先にオブジェクトがある場合、押す
                    float to = PhysicsCaster.hits[i].collider.bounds.center.x - StellaMove.instance.transform.position.x;
                    if (StellaMove.myVelocity.x * to > 0f)
                    {
                        StellaMove.ChrController.stepOffset = PushStepOffset;
                        if (!acts[j].PushAction())
                        {
                            continue;
                        }
                    }

                    // 向いている方向に対象物がある時、対象物に触れていたらステラを下げる
                    float range = StellaMove.ChrController.bounds.extents.x + PhysicsCaster.hits[i].collider.bounds.extents.x + StellaMove.CollisionMargin;
                    if (((to * StellaMove.forwardVector.x) > 0f) && (Mathf.Abs(to) < range))
                    {
                        float posx = PhysicsCaster.hits[i].collider.bounds.center.x - range * StellaMove.forwardVector.x;
                        StellaMove.myVelocity.x = (posx - StellaMove.instance.transform.position.x) / Time.fixedDeltaTime;
                        isBack = true;
                    }
                }
            }

            return(isBack);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 真下が岩以外なら、trueを返します、
        /// </summary>
        bool NotOnRock()
        {
            int hitCount = PhysicsCaster.CharacterControllerCast(StellaMove.chrController, Vector3.down, getOffDistance, PhysicsCaster.MapCollisionLayer);

            for (int i = 0; i < hitCount; i++)
            {
                if (PhysicsCaster.hits[i].collider.CompareTag("Rock"))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        /// <summary>
        /// ツタと重なっているかを確認します。重なっていたら、ツタのインスタンスを返します。
        /// </summary>
        /// <returns>見つけたツタのインスタンス。なければnull</returns>
        static Ivy CheckIvyOverlap()
        {
            int hitCount = PhysicsCaster.CharacterControllerCast(ChrController, Vector3.down, 0f, PhysicsCaster.MapLayer, QueryTriggerInteraction.Collide);

            for (int i = 0; i < hitCount; i++)
            {
                Ivy ivy = PhysicsCaster.hits[i].collider.GetComponent <Ivy>();
                if (ivy != null)
                {
                    return(ivy);
                }
            }

            return(null);
        }
Exemplo n.º 5
0
        public override void UpdateAction()
        {
            // つた掴みチェック
            if (StellaMove.CheckIvyHold())
            {
                return;
            }

            // 行動ボタンチェック。着地時は何もしない
            if (Input.GetButton("Action") && !isLanding)
            {
                Actable act = StellaMove.ActionBoxInstance.GetActableInstance();
                if (act != null)
                {
                    if (act.Action())
                    {
                        return;
                    }
                }
            }

            StellaMove.instance.Gravity();
            StellaMove.instance.Move();

            // 着地チェック
            bool isGrounded = StellaMove.ChrController.isGrounded;

            if (!isGrounded && (StellaMove.myVelocity.y < 0))
            {
                int hitCount = PhysicsCaster.CharacterControllerCast(
                    StellaMove.ChrController,
                    Vector3.down,
                    StellaMove.CollisionMargin,
                    PhysicsCaster.MapCollisionPlayerOnlyLayer);
                for (int i = 0; i < hitCount; i++)
                {
                    if (!PhysicsCaster.hits[i].collider.isTrigger)
                    {
                        isGrounded = true;
                    }
                }
            }

            // 着地チェック
            if (!isLanding && isGrounded && StellaMove.myVelocity.y < 0f)
            {
                SoundController.Play(SoundController.SeType.Landing);

                StellaMove.myVelocity.x = 0;
                StellaMove.RegisterAnimEvent(Grounded);
                isLanding = true;
                StellaMove.CheckStepOn();

                StageManager.SetFollowCameraTarget(StellaMove.instance.transform);
            }
            // 頭ぶつけチェック
            else if ((StellaMove.myVelocity.y > 0f) && StellaMove.IsHitHead)
            {
                SoundController.Play(SoundController.SeType.HitHead);
                StellaMove.myVelocity.y = 0f;
            }
        }
Exemplo n.º 6
0
        public override void UpdateAction()
        {
            // キーの入力を調べる
            float h = Input.GetAxisRaw("Horizontal");

            // 左右の移動速度(秒速)を求める
            StellaMove.myVelocity.x = h * StellaMove.MoveSpeed;

            StellaMove.instance.Gravity();
            Log($"A: Stella={StellaMove.instance.transform.position.x}, {StellaMove.instance.transform.position.y} {StellaMove.myVelocity.x}, {StellaMove.myVelocity.y} rock={rockActable.transform.position.x}, {rockActable.transform.position.y}");
            StellaMove.instance.Move();
            Log($"B: Stella={StellaMove.instance.transform.position.x}, {StellaMove.instance.transform.position.y} isGrounded={StellaMove.chrController.isGrounded}");

            // 逆再生設定
            bool back = h * StellaMove.forwardVector.x < -0.5f;

            StellaMove.SetAnimBool("Back", back);

            if (!StellaMove.chrController.isGrounded)
            {
                /// 下に岩があればセーフ
                int hitCount = PhysicsCaster.CharacterControllerCast(
                    StellaMove.chrController, Vector3.down, CheckFallHeight, PhysicsCaster.MapCollisionLayer);
                bool isRock = false;
                for (int i = 0; i < hitCount; i++)
                {
                    if (PhysicsCaster.hits[i].collider.CompareTag("Rock"))
                    {
                        isRock = true;
                        break;
                    }
                }

                if (!isRock)
                {
                    StellaMove.instance.ChangeAction(StellaMove.ActionType.Air);
                    FallNextBlock();
                    Log($"C: Stella={StellaMove.instance.transform.position.x}, {StellaMove.instance.transform.position.y}");
                }
            }
            else
            {
                // 真下が岩以外なら、他の行動へ
                if (NotOnRock())
                {
                    StellaMove.instance.ChangeToWalk();
                    Log($"D: Stella={StellaMove.instance.transform.position.x}, {StellaMove.instance.transform.position.y}");
                }

                // 乗り換えチェック
                if (lastRockObject != StellaMove.stepOnObject)
                {
                    Log($"  乗り換え");
                    lastRockObject = StellaMove.stepOnObject;
                    rockActable    = lastRockObject.GetComponent <RockActable>();
                    rockCollider   = lastRockObject.GetComponent <SphereCollider>();
                }

                // 岩に力を加える
                if (rockActable != null)
                {
                    Vector3 lastPos = lastRockObject.transform.position;
                    float   dist    = StellaMove.instance.transform.position.x - lastPos.x;
                    if (dist < -changeDistance)
                    {
                        StellaMove.myVelocity.x = -rockSpeed[1];
                    }
                    else if (dist > changeDistance)
                    {
                        StellaMove.myVelocity.x = rockSpeed[1];
                    }
                    else
                    {
                        StellaMove.myVelocity.x = rockSpeed[0] * Mathf.Sign(dist);
                    }

                    // ステラが移動できるか確認
                    int hitCount = PhysicsCaster.CharacterControllerCast(
                        StellaMove.chrController,
                        StellaMove.myVelocity.x < 0f ? Vector3.left : Vector3.right,
                        Mathf.Abs(StellaMove.myVelocity.x) * Time.fixedDeltaTime,
                        PhysicsCaster.MapCollisionLayer);
                    bool blocked = false;
                    for (int i = 0; i < hitCount; i++)
                    {
                        if (PhysicsCaster.hits[i].collider.gameObject != lastRockObject)
                        {
                            // ぶつかるなら移動キャンセル
                            StellaMove.myVelocity.x = 0f;
                            blocked = true;
                            break;
                        }
                    }

                    // 岩を移動させる
                    if (!blocked)
                    {
                        StellaMove.chrController.enabled = false;
                        rockActable.PushAction();
                        Log($"F: Stella={StellaMove.instance.transform.position.x}, {StellaMove.instance.transform.position.y}");

                        // ステラの座標を修正する
                        Vector3 stellaMove = Vector3.zero;
                        float   moved      = lastRockObject.transform.position.x - lastPos.x;
                        float   rad        = moved / rockCollider.radius;
                        stellaMove.Set(
                            moved + Mathf.Sin(rad) * rockCollider.radius,
                            StellaMove.chrController.skinWidth * 1.5f,
                            0f);
                        Log($"  moved={moved}={lastRockObject.transform.position.x}-{lastPos.x} / rad={rad} / sin={Mathf.Sin(rad)} / rockrad={rockCollider.radius} / Stella={StellaMove.instance.transform.position.x}, {StellaMove.instance.transform.position.y}");
                        StellaMove.chrController.enabled = true;
                        StellaMove.chrController.Move(stellaMove);
                        Log($"  moved2 Stella={StellaMove.instance.transform.position.x}, {StellaMove.instance.transform.position.y}");
                        // 着地
                        stellaMove.Set(0, -StellaMove.chrController.stepOffset, 0);
                        StellaMove.chrController.Move(stellaMove);
                        Log($"G: Stella={StellaMove.instance.transform.position.x}, {StellaMove.instance.transform.position.y} move={stellaMove.x}, {stellaMove.y} isGrounded={StellaMove.chrController.isGrounded} / rock={rockActable.transform.position.x}, {rockActable.transform.position.y}");

                        // 足元に岩が無ければ飛び降りる
                        if (!CheckGetOff())
                        {
                            Log($"H: {StellaMove.instance.transform.position}");
                            return;
                        }
                    }
                }

                // 操作していればジャンプチェック
                if (!Mathf.Approximately(h, 0f))
                {
                    StellaMove.instance.CheckMiniJump();
                    Log($"I: {StellaMove.instance.transform.position}");
                }
            }
        }
Exemplo n.º 7
0
        public override void UpdateAction()
        {
            StellaMove.ZyouroEmitter.transform.position = StellaMove.ZyouroEmitterPosition.position;

            if (state == StateType.Action)
            {
                // 水オブジェクトを生成
                if (Time.time - lastTriggerTime >= triggerEmitSeconds)
                {
                    lastTriggerTime = Time.time;
                    triggerObjects[triggerIndex].SetActive(true);
                    triggerObjects[triggerIndex].transform.position = StellaMove.ZyouroEmitterPosition.position;
                    triggerRigidbody[triggerIndex].velocity         = StellaMove.ZyouroEmitter.forward * triggerSpeed;
                    triggerWater[triggerIndex].Start();
                    triggerIndex = (triggerIndex + 1) % TriggerCount;
                }

                // 水まき終了チェック
                if (!Input.GetButton("Water") && (Grow.WaitGrowCount <= 0))
                {
                    // 水まき終了
                    state = StateType.End;
                    StellaMove.SetAnimState(StellaMove.AnimType.Walk);
                    StellaMove.RegisterAnimEvent(EndAction);
                    zyouroParticle.Stop();
                    StellaMove.WaterSeStop();
                    return;
                }

                // 効果音
                if ((Time.time - lastSeTime) >= waterSeSeconds)
                {
                    lastSeTime = Time.time;
                    StellaMove.WaterSePlay();
                }

                // 後ずさりチェック
                int hitCount = PhysicsCaster.CharacterControllerCast(StellaMove.ChrController, Vector3.down, 0f, PhysicsCaster.MapCollisionPlayerOnlyLayer);

                for (int i = 0; i < hitCount; i++)
                {
                    // 下げる
                    float colx   = PhysicsCaster.hits[i].collider.bounds.extents.x;
                    float dist   = StellaMove.ChrController.radius + colx + StellaMove.CollisionMargin;
                    float target = PhysicsCaster.hits[i].transform.position.x - dist * StellaMove.forwardVector.x;
                    float move   = target - StellaMove.instance.transform.position.x;
                    if (move * StellaMove.forwardVector.x >= 0f)
                    {
                        // 向いている方向には動かさない
                        return;
                    }
                    StellaMove.myVelocity.x = move / Time.fixedDeltaTime;
                    Vector3 lastPos = StellaMove.instance.transform.position;
                    StellaMove.instance.Move();
                    lastPos.x = StellaMove.instance.transform.position.x;
                    StellaMove.instance.transform.position = lastPos;
                    StellaMove.myVelocity.x = 0f;
                }
            }
            else
            {
                StellaMove.instance.Gravity();
                StellaMove.instance.Move();
            }
        }