private IEnumerator act()
        {
            const float RANGE = 300f;

            for (var i = 0; i < 100; ++i)
            {
                var position = new Vector3(MyRandom.Probability(0.5f) ? -RANGE : RANGE,
                                           MyRandom.Range(-RANGE, RANGE),
                                           MyRandom.Range(-RANGE, RANGE));
                var rotation = Quaternion.LookRotation(MyRandom.onSphere(1f));
                Fighter.create(Fighter.Type.Alpha, ref position, ref rotation, update_time_);
            }
            for (;;)
            {
                yield return(null);
            }
        }
        private void alpha_update(float dt, double update_time)
        {
            if (MissileManager.Instance.checkHitAndClear(target_id_))
            {
                hit_time_ = update_time;
            }
            if (update_time - hit_time_ < 0.5f)
            {
                rigidbody_.setRotateDamper(0.2f);
                if (update_time - hit_time_ < 0.017f)
                {
                    var torque = MyRandom.onSphere(25f);
                    rigidbody_.addTorque(ref torque);
                }
            }
            else
            {
                rigidbody_.setRotateDamper(1f);
                alpha_normal_act(dt, update_time);
            }

            rigidbody_.update(dt);
        }
Esempio n. 3
0
        void OnGUI()
        {
            int x = 20;
            int y = 60;
            int w = 240;
            int h = 40;

            GUI.Box(new Rect(Screen.width - (x + w + 10), y - 40, w, y + h * 10 + 10), "Posture Param");
            GUI.Label(new Rect(Screen.width - (x + w), y, w - 20, h), "body damper");
            y += h / 2;
            float body_damper = GUI.HorizontalSlider(new Rect(Screen.width - (x + w), y, w - 20, h), body_damper_, 0f, 100f);

            if (body_damper_ != body_damper)
            {
                body_damper_ = body_damper;
            }
            y += h;
            GUI.Label(new Rect(Screen.width - (x + w), y, w - 20, h), "body spring");
            y += h / 2;
            float body_spring = GUI.HorizontalSlider(new Rect(Screen.width - (x + w), y, w - 20, h), body_spring_, 0f, 2000f);

            if (body_spring_ != body_spring)
            {
                body_spring_ = body_spring;
            }
            y += h;
            GUI.Label(new Rect(Screen.width - (x + w), y, w - 20, h), "arm damper");
            y += h / 2;
            float arm_damper = GUI.HorizontalSlider(new Rect(Screen.width - (x + w), y, w - 20, h), arm_damper_, 0f, 100f);

            if (arm_damper_ != arm_damper)
            {
                arm_damper_ = arm_damper;
            }
            y += h;
            GUI.Label(new Rect(Screen.width - (x + w), y, w - 20, h), "arm spring");
            y += h / 2;
            float arm_spring = GUI.HorizontalSlider(new Rect(Screen.width - (x + w), y, w - 20, h), arm_spring_, 0f, 2000f);

            if (arm_spring_ != arm_spring)
            {
                arm_spring_ = arm_spring;
            }
            y += h;
            GUI.Label(new Rect(Screen.width - (x + w), y, w - 20, h), "leg damper");
            y += h / 2;
            float leg_damper = GUI.HorizontalSlider(new Rect(Screen.width - (x + w), y, w - 20, h), leg_damper_, 0f, 100f);

            if (leg_damper_ != leg_damper)
            {
                leg_damper_ = leg_damper;
            }
            y += h;
            GUI.Label(new Rect(Screen.width - (x + w), y, w - 20, h), "leg spring");
            y += h / 2;
            float leg_spring = GUI.HorizontalSlider(new Rect(Screen.width - (x + w), y, w - 20, h), leg_spring_, 0f, 2000f);

            if (leg_spring_ != leg_spring)
            {
                leg_spring_ = leg_spring;
            }
            y += h;


            x = 20;
            y = 40;
            w = 180;
            h = 30;
            GUI.Box(new Rect(x - 10, y - 20, x + w, y + h * 10 + 10), "Posture Menu");

            if (GUI.Button(new Rect(x, y, w, h), "apose") || Input.GetKeyDown(KeyCode.Alpha0))
            {
                current_posture_ = posture_apose_;
            }
            y += h;
            if (GUI.Button(new Rect(x, y, w, h), "pre_throw_l_arm") || Input.GetKeyDown(KeyCode.Alpha1))
            {
                current_posture_ = posture_pre_throw_l_arm_;
            }
            y += h;
            if (GUI.Button(new Rect(x, y, w, h), "throw_l_arm") || Input.GetKeyDown(KeyCode.Alpha2))
            {
                current_posture_ = posture_throw_l_arm_;
            }
            y += h;
            if (GUI.Button(new Rect(x, y, w, h), "pre_throw_r_arm") || Input.GetKeyDown(KeyCode.Alpha3))
            {
                current_posture_ = posture_pre_throw_r_arm_;
            }
            y += h;
            if (GUI.Button(new Rect(x, y, w, h), "throw_r_arm") || Input.GetKeyDown(KeyCode.Alpha4))
            {
                current_posture_ = posture_throw_r_arm_;
            }
            y += h;
            if (GUI.Button(new Rect(x, y, w, h), "pre_jump") || Input.GetKeyDown(KeyCode.Alpha5))
            {
                current_posture_ = posture_pre_jump_;
            }
            y += h;
            if (GUI.Button(new Rect(x, y, w, h), "hit") || Input.GetKeyDown(KeyCode.Alpha6))
            {
                var torque0 = MyRandom.onSphere(1f) * 2000f;
                muscle_motion_.getNode(MuscleMotion.Parts.Ribs).rigidbody_.addTorque(ref torque0);
                var torque1 = MyRandom.onSphere(1f) * 2000f;
                muscle_motion_.getNode(MuscleMotion.Parts.Ribs2).rigidbody_.addTorque(ref torque1);
                var torque2 = MyRandom.onSphere(1f) * 2000f;
                muscle_motion_.getNode(MuscleMotion.Parts.Ribs3).rigidbody_.addTorque(ref torque2);
            }
            y += h;

            y          += 8;
            gui_lookat_ = GUI.HorizontalSlider(new Rect(x, y, w, h), gui_lookat_, 0f, 1f);
            y          += 10;
            GUI.Label(new Rect(x, y, w, h), "value:" + gui_lookat_);
            y          += h;
            gui_hand_   = GUI.Toggle(new Rect(x, y, w, h), gui_hand_, "hand");
            y          += h;
            gui_rotate_ = GUI.Toggle(new Rect(x, y, w, h), gui_rotate_, "rotate");
            y          += h;
        }
Esempio n. 4
0
        public override void update(float dt, double update_time)
        {
            var controller = Controller.Instance.getLatest();

            muscle_motion_.setTarget(posture_apose_);
            if (controller.isLeftButtonUp())
            {
                throwing_cnt_l_ = (int)(0.5f / dt);
            }
            if (controller.isRightButtonUp())
            {
                throwing_cnt_r_ = (int)(0.5f / dt);
            }
            if (throwing_cnt_l_ > 0)
            {
                muscle_motion_.setTarget(posture_throw_l_arm_);
                // muscle_motion_.addTorqueY(MuscleMotion.Parts.Ribs2, 8000f);
                // muscle_motion_.addTorqueY(MuscleMotion.Parts.Hip, 8000f);
                // muscle_motion_.addTorqueX(MuscleMotion.Parts.L_Thigh, 8000f);
                // muscle_motion_.addTorqueX(MuscleMotion.Parts.L_Knee, 8000f);
                if (throwing_cnt_l_ < (int)(0.45f / dt))
                {
                    fire_left(update_time);
                }
                --throwing_cnt_l_;
            }
            if (throwing_cnt_r_ > 0)
            {
                muscle_motion_.setTarget(posture_throw_r_arm_);
                // muscle_motion_.addTorqueY(MuscleMotion.Parts.Ribs2, -8000f);
                // muscle_motion_.addTorqueY(MuscleMotion.Parts.Hip, -8000f);
                // muscle_motion_.addTorqueX(MuscleMotion.Parts.R_Thigh, 8000f);
                // muscle_motion_.addTorqueX(MuscleMotion.Parts.R_Knee, 8000f);
                if (throwing_cnt_r_ < (int)(0.45f / dt))
                {
                    fire_right(update_time);
                }
                --throwing_cnt_r_;
            }
            if (controller.isLeftButtonDown())
            {
                MuscleMotion.Node node = muscle_motion_.getNode(MuscleMotion.Parts.L_Wrist);
                fire_left(update_time);
                left_held_bullet_ = Bullet.create(ref node.rigidbody_.transform_.position_,
                                                  ref CV.QuaternionIdentity);
            }
            if (controller.isRightButtonDown())
            {
                MuscleMotion.Node node = muscle_motion_.getNode(MuscleMotion.Parts.R_Wrist);
                fire_right(update_time);
                right_held_bullet_ = Bullet.create(ref node.rigidbody_.transform_.position_,
                                                   ref CV.QuaternionIdentity);
            }
            if (controller.isLeftButton())
            {
                throwing_cnt_l_  = 0;
                throwing_cnt_r_ -= (int)(0.25f / dt);
                muscle_motion_.setTarget(posture_pre_throw_l_arm_);
                bullet_tame_left_ += dt;
            }
            if (controller.isRightButton())
            {
                throwing_cnt_l_ -= (int)(0.25f / dt);
                throwing_cnt_r_  = 0;
                muscle_motion_.setTarget(posture_pre_throw_r_arm_);
                bullet_tame_right_ += dt;
            }
            if (left_held_bullet_ != null)
            {
                MuscleMotion.Node node = muscle_motion_.getNode(MuscleMotion.Parts.L_Wrist);
                left_held_bullet_.setPosition(ref node.rigidbody_.transform_.position_);
                left_held_bullet_.setPower(Mathf.Clamp(bullet_tame_left_, 0.25f, 2f));
            }
            if (right_held_bullet_ != null)
            {
                MuscleMotion.Node node = muscle_motion_.getNode(MuscleMotion.Parts.R_Wrist);
                right_held_bullet_.setPosition(ref node.rigidbody_.transform_.position_);
                right_held_bullet_.setPower(Mathf.Clamp(bullet_tame_right_, 0.25f, 2f));
            }

            if (controller.isJumpButton() && on_ground_)
            {
                muscle_motion_.getRootNode().rigidbody_.addRelativeTorqueX(1000f);
                muscle_motion_.setTarget(posture_pre_jump_,
                                         MuscleMotion.PartsBit.LowerBody |
                                         MuscleMotion.PartsBit.Ribs |
                                         MuscleMotion.PartsBit.Ribs2 |
                                         MuscleMotion.PartsBit.Ribs3);
                jump_tame_duration_ += dt;
            }

            if (controller.isJumpButtonUp())
            {
                if (jump_tame_duration_ > 0.5f)
                {
                    jump_propel_remain_ = Mathf.Min((jump_tame_duration_ - 0.5f) + 0.5f, 1f) * 2f;
                    rigidbody_.addForceY(1000f);
                    WaterSurface.Instance.makeBump(ref rigidbody_.transform_.position_,
                                                   -1f /* value */, 1f /* size */);
                    on_ground_time_ = 0f;
                    somersault_     = MyRandom.Probability(0.25f);
                }
                jump_tame_duration_ = 0f;
            }

            float hori          = controller.getHorizontal();
            float ground_height = 1.25f;

            if (hori != 0f)
            {
                ground_height = 1f;
            }

            if (jump_propel_remain_ > 0f)
            {
                rigidbody_.addForceY(100f);
                jump_propel_remain_ -= dt;
            }
            on_ground_ = (rigidbody_.transform_.position_.y <= 1f);

            rigidbody_.addTargetTorque(ref look_at_, 500f /* torque_level */, -1f /* max_level */);
            rigidbody_.addRelativeForceX(hori * 64f);
            if (hori != 0f)
            {
                rigidbody_.addRelativeForceZ(10f);
            }
            rigidbody_.addForceY(-9.8f * 5f);   // gravity
            if (rigidbody_.transform_.position_.y < ground_height)
            {
                rigidbody_.addSpringForceY(ground_height, 100f);
            }
            rigidbody_.solveForGround(0.0f /* ground_height */, dt);
            rigidbody_.addRelativeTorqueZ(-hori * 100f);
            {
                var forward = rigidbody_.transform_.rotation_ * CV.Vector3Forward;
                var q       = Quaternion.LookRotation(forward);
                rigidbody_.addSpringTorque(ref q, 10000f);
            }
            rigidbody_.update(dt);

            if (rigidbody_.transform_.position_.y < 5f)
            {
                WaterSurface.Instance.makeBump(ref rigidbody_.transform_.position_, -0.05f /* value */, 0.6f /* size */);
                var pos = rigidbody_.transform_.position_;
                pos.y = -2f;
                float vel_y;
                if (hori != 0f)
                {
                    vel_y = MyRandom.Range(7f, 9f);
                }
                else
                {
                    vel_y = MyRandom.Range(5f, 7f);
                }
                var vel = new Vector3(0f,
                                      vel_y,
                                      0f);
                if (MyRandom.Probability(0.2f))
                {
                    WaterSplash.Instance.spawn(ref pos, ref vel, update_time);
                }
            }

            var root_node = muscle_motion_.getRootNode();

            root_node.rigidbody_.transform_.position_ =
                rigidbody_.transform_.position_ + new Vector3((Mathf.PerlinNoise((float)update_time * 4f, 0.0f) - 0.5f) * 0.04f,
                                                              (Mathf.PerlinNoise((float)update_time * 4f, 0.5f) - 0.5f) * 0.04f,
                                                              (Mathf.PerlinNoise((float)update_time * 4f, 1.0f) - 0.5f) * 0.04f);

            if (somersault_ && on_ground_time_ < 0.25f)
            {
                root_node.rigidbody_.addRelativeTorqueX(-3000f);
                muscle_motion_.getNode(MuscleMotion.Parts.Ribs).rigidbody_.addRelativeTorqueX(-3000f);
                muscle_motion_.getNode(MuscleMotion.Parts.Ribs2).rigidbody_.addRelativeTorqueX(-3000f);
                muscle_motion_.getNode(MuscleMotion.Parts.Ribs3).rigidbody_.addRelativeTorqueX(-3000f);
                muscle_motion_.getNode(MuscleMotion.Parts.Hip).rigidbody_.addRelativeTorqueX(-3000f);
            }
            else
            {
                root_node.rigidbody_.addTorqueY(hori * 1000f);
                root_node.rigidbody_.addRelativeTorqueZ(-hori * 1000f);
                root_node.rigidbody_.addSpringTorque(ref rigidbody_.transform_.rotation_, 4000f);
            }

            muscle_motion_.addTorqueX(MuscleMotion.Parts.L_Tale1, MyRandom.Range(500f, 1200f));
            muscle_motion_.addTorqueX(MuscleMotion.Parts.L_Tale4, MyRandom.Range(-4000f, 4000f));
            muscle_motion_.addTorqueX(MuscleMotion.Parts.R_Tale1, MyRandom.Range(500f, 1200f));
            muscle_motion_.addTorqueX(MuscleMotion.Parts.R_Tale4, MyRandom.Range(-4000f, 4000f));
            muscle_motion_.addTorqueX(MuscleMotion.Parts.L_SusoBack, MyRandom.Range(300f, 600f));
            muscle_motion_.addTorqueX(MuscleMotion.Parts.L_SusoFront, MyRandom.Range(-600f, -300f));
            muscle_motion_.addTorqueX(MuscleMotion.Parts.R_SusoBack, MyRandom.Range(300f, 600f));
            muscle_motion_.addTorqueX(MuscleMotion.Parts.R_SusoFront, MyRandom.Range(-600f, -300f));

            Vector3 e_pos;

            if (jump_tame_duration_ > 0.75f || on_ground_time_ < 1f)
            {
                var node = muscle_motion_.getNode(MuscleMotion.Parts.Head);
                node.rigidbody_.addRelativeTorqueX(-4000f);
            }
            else if (MyCollider.getNearestEnemyPosition(out e_pos))
            {
                muscle_motion_.getNode(MuscleMotion.Parts.Head).rigidbody_.addSpringTorque(ref e_pos, 4000f);
            }

            {
                var intersect_point = CV.Vector3Zero;
                if (MyCollider.getHitOpponentForPlayer(collider_, ref intersect_point) == MyCollider.Type.EnemyBullet)
                {
                    var node   = muscle_motion_.getNode(MuscleMotion.Parts.Ribs3);
                    var torque = MyRandom.onSphere(1f) * 5000f;
                    node.rigidbody_.addTorque(ref torque);
                    Shield.Instance.spawn(ref intersect_point,
                                          ref rigidbody_.transform_.position_,
                                          update_time,
                                          Shield.Type.Green);
                    SystemManager.Instance.registSound(DrawBuffer.SE.Shield);
                    // hit_time_ = (float)update_time;
                    // hit_position_ = intersect_point;
                }
                MyCollider.updatePlayer(collider_, ref rigidbody_.transform_.position_);
            }

            muscle_motion_.update(dt);
            on_ground_time_ += dt;
        }