Esempio n. 1
0
        public override void OnUpdate()
        {
            if (Input.GetAction("Fire") && Time.GameTime >= _timeToFire)
            {
                _timeToFire = Time.GameTime + 1.0f / _data.FireRate;

                var bullet = new RigidBody
                {
                    Name        = "Bullet",
                    StaticFlags = StaticFlags.None,
                    UseCCD      = true,
                };

                new StaticModel
                {
                    Model       = _data.BulletModel,
                    Parent      = bullet,
                    StaticFlags = StaticFlags.None
                };

                // Ideally you would also use raycasting to determine if something was hit
                new SphereCollider
                {
                    Parent      = bullet,
                    StaticFlags = StaticFlags.None
                };

                bullet.Transform = new Transform(BulletSpawnPoint.Position, Quaternion.Identity, _data.BulletScale);
                Level.SpawnActor(bullet);

                bullet.LinearVelocity = BulletSpawnPoint.Direction * _data.BulletVelocity;

                Destroy(bullet, _data.BulletLifetime);
            }
        }