Esempio n. 1
0
        public override void update(float dt, double update_time)
        {
            if (is_held_)
            {
                return;
            }

            if (MyCollider.isDisabledBullet(collider_) && update_time - start_ > 0.1)
            {
                MyCollider.disableForBullet(collider_, false);
            }

            var collider_type = MyCollider.getHitOpponentForBullet(collider_);

            if (collider_type != MyCollider.Type.None)
            {
                if (collider_type == MyCollider.Type.EnemyHoming)
                {
                    Vector3 target;
                    MyCollider.getHitOpponentInfoPositionForBullet(collider_, out target);
                    var diff = target - rigidbody_.transform_.position_;
                    Vector3.Normalize(diff);
                    const float speed = 10f;
                    diff *= speed;
                    rigidbody_.setVelocity(ref diff);
                }
                else
                {
                    Spark.Instance.spawn(ref rigidbody_.transform_.position_, Spark.Type.Bullet, update_time);
                    destroy();
                    return;
                }
            }

            if (rigidbody_.transform_.position_.y < 0f)
            {
                WaterSurface.Instance.makeBump(ref rigidbody_.transform_.position_, 0.5f /* value */, 1f /* size */);
                destroy();
                var pos = new Vector3(rigidbody_.transform_.position_.x, -0.5f, rigidbody_.transform_.position_.z);
                for (var i = 0; i < 8; ++i)
                {
                    var spread = 2f;
                    var vel    = new Vector3(Mathf.Cos(i * Mathf.PI * (2f / 8f)) * spread,
                                             MyRandom.Range(5f, 7f),
                                             Mathf.Sin(i * Mathf.PI * (2f / 8f)) * spread);
                    WaterSplash.Instance.spawn(ref pos, ref vel, update_time);
                }
                return;
            }

            prev_position_ = rigidbody_.transform_.position_;
            rigidbody_.update(dt);
            MyCollider.updateBullet(collider_, ref rigidbody_.transform_.position_);

            if (update_time - start_ > MyRandom.Range(2f, 2.5f))       // 寿命
            {
                destroy();
                return;
            }
        }