private void CreateProjectile()
        {
            for (int cntr = 0; cntr < 30; cntr++)
            {
                Projectile projectile = new Projectile(StaticRandom.NextDouble(.1, .5), 1000, new Point3D(15, 0, 0) + Math3D.GetRandomVector_Circular(3), _world, _material_Projectile, _itemOptions.Projectile_Color);

                projectile.PhysicsBody.AngularVelocity = Math3D.GetRandomVector_Spherical(6);

                _map.AddItem(projectile);
            }
        }
Esempio n. 2
0
        public Vector3D Fire()
        {
            if(this.IsDestroyed)
            {
                return new Vector3D(0, 0, 0);
            }

            #region Pull ammo

            var projProps = _projectileProps;
            if (projProps == null)
            {
                // The caliber hasn't been set yet (a default is set in the constructor, so this should never happen)
                return new Vector3D(0, 0, 0);
            }

            IContainer ammo = this.Ammo;
            if (ammo == null)
            {
                // No ammo
                return new Vector3D(0, 0, 0);
            }

            // Pull from ammo
            if (ammo.RemoveQuantity(projProps.AmountToPull, true) > 0)
            {
                // Not enough ammo
                return new Vector3D(0, 0, 0);
            }

            #endregion

            #region Get position/direction

            // Model coords
            Point3D modelPosition = this.Design.Position;

            double length = this.Design.Scale.Z / 2d;
            length *= 3;     // make it a bit longer so it doesn't collide with the gun
            Vector3D modelDirection = new Vector3D(0, 0, length);

            // World coords
            var worldLoc = GetWorldLocation();
            var worldSpeed = GetWorldSpeed(null);

            Vector3D worldDirection = worldLoc.Item2.GetRotatedVector(modelDirection);
            Vector3D worldDirectionUnit = worldDirection.ToUnit();

            Point3D worldPosition = worldLoc.Item1 + worldDirection;

            #endregion

            // Create the projectile
            Projectile projectile = new Projectile(projProps.Radius, projProps.Mass, worldPosition, _world, _material_Projectile, _itemOptions.Projectile_Color, projProps.MaxAge, _map);

            projectile.PhysicsBody.Velocity = worldSpeed.Item1 + (worldDirectionUnit * projProps.Speed);
            projectile.PhysicsBody.AngularVelocity = worldDirectionUnit * 5;        // add a little spin along the direction of travel (emulate rifling)

            _map.AddItem(projectile);

            // Calculate Kick
            //TODO: May want to add a bit extra to emulate the expanding gas pushing the gun bag after the bullet leaves the barrel
            double mult = 1000;
            //return -worldDirectionUnit * projProps.Speed * projProps.Mass * mult;
            return _kickDirectionUnit * projProps.Speed * projProps.Mass * mult;
        }