Exemplo n.º 1
0
        /*---Creates a new grenade object---*/
        public static GrenadeObject CreateNew(Vector3 position, Quaternion rotation, ShipRefs owner)
        {
            // create object
            CustomPrefab  grenadePrefab = Instantiate(GrenadeMod.GrenadePrefab);
            GrenadeObject grenade       = grenadePrefab.gameObject.AddComponent <GrenadeObject>();

            grenade.Owner = owner;

            // setup the grenades transform
            grenade.transform.position = position;
            grenade.transform.rotation = rotation;

            // get the components from the custom prefab and apply them to the grenade
            MeshRenderer grenadeRenderer     = grenadePrefab.GetComponent <MeshRenderer>("Mesh");
            BoxCollider  shipCollider        = grenadePrefab.GetComponent <BoxCollider>("ShipCollider");
            BoxCollider  environmentCollider = grenadePrefab.GetComponent <BoxCollider>("EnvCollider");

            // setup Components
            environmentCollider.gameObject.layer = LayerMask.NameToLayer("Weapon"); // the weapon layer only collides with scenery

            // setup speed
            float velBasedSpeed = owner.InverseTransformDirection(owner.RBody.velocity).z *ConfigSpeed * 0.06f;

            grenade.StatSpeed = Mathf.Max(ConfigSpeed, velBasedSpeed);

            // setup other stats
            grenade.ImpactSettings  = ConfigImpactSettings;
            grenade.StatLifetime    = ConfigLifetime;
            grenade.StatGravity     = ConfigGravity;
            grenade.StatBounceForce = ConfigBounceForce;
            grenade.StatMaxBounces  = ConfigMaxBounces;

            // setup Colliders
            grenade.ShipCollider           = shipCollider;
            grenade.EnvironmentCollider    = environmentCollider;
            grenade.ProjectileMeshRenderer = grenadeRenderer;

            // cache transform of the grenade mesh object.
            grenade.GrenadeMeshT = grenadeRenderer.transform;

            // assign explosion prefab
            grenade.PrefabExplosion = GrenadeMod.ExposionPrefab;

            grenade.ConfigureProjectile(owner.CollisionMeshObject, grenade.StatSpeed, owner);

            // check if there is environment between the ship and grenade spawn position and destroy the grenade if there is
            bool envBlockingGrenade = Physics.Linecast(owner.RBody.position, position, Layers.FloorMask | Layers.TrackWall);

            if (envBlockingGrenade)
            {
                grenade.DestroyProjectile(null);
            }

            return(grenade);
        }
Exemplo n.º 2
0
        /*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        *  Spawns a new set of grenades. networkSpawn allows us to determine if the server is spawning the grenades and if it's a local spawn, we'll tell the server we've fired grenades
        *  ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
        public static void CreateGrenade(ShipRefs ship)
        {
            // if we're a player then play a 2D deployment sound
            if (ship.IsPlayer)
            {
                AudioHelpers.PlayOneShot(AudioHelpers.GetAudioClip(AudioHelpers.Weapons_MineDrop), AudioHelpers.E_AUDIOCHANNEL.SFX, 1.0f, 1.0f);
            }

            // create the grenades
            GrenadeObject.CreateNew(ship.transform.TransformPoint(-GrenadeSpawnSpread, 0.0f, ship.MeshBoundsFront.z), ship.RBody.rotation, ship);
            GrenadeObject.CreateNew(ship.transform.TransformPoint(0.0f, 0.0f, 1.0f), ship.RBody.rotation, ship);
            GrenadeObject.CreateNew(ship.transform.TransformPoint(GrenadeSpawnSpread, 0.0f, ship.MeshBoundsFront.z), ship.RBody.rotation, ship);
        }