/*------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ * 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); }
/*----------------------------------------------------------------------------------------------------------------------- * Assuming the prefab is setup correctly with the environment collider being solid and the ship collider being a trigger, * this will trigger when the environment collider starts to collide with something. * ----------------------------------------------------------------------------------------------------------------------*/ private void OnCollisionEnter(Collision other) { int otherLayer = other.gameObject.layer; /*------------------------------------------------------ * Determine if we've hit the track or floor. * We could also determine if we hit a wall by using: * * bool hitwall = otherLayer == LayerIDs.TrackWall; * -----------------------------------------------------*/ bool hitFloor = otherLayer == LayerIDs.SmoothFloor || other.gameObject.layer == LayerIDs.FakeFloor || other.gameObject.layer == LayerIDs.TrackFloor; // reflect the grenade if (hitFloor) { Vector3 bounceNormal = other.contacts[0].normal; // reflect the forward vector of the grenade Vector3 forward = transform.forward; forward = Vector3.Reflect(forward, bounceNormal); transform.forward = forward; Body.AddForce(bounceNormal * StatBounceForce, ForceMode.VelocityChange); StatBounceForce *= 0.9f; // play Impact Sound AudioHelpers.PlayOneShot(AudioHelpers.GetAudioClip(AudioHelpers.Ship_FloorHit), AudioHelpers.E_AUDIOCHANNEL.SFX, 0.4f, 1.0f, transform.position, null, 15.0f, 30.0f); if (BounceCount > StatMaxBounces) { DestroyProjectile(null); } // temporary bounce count immunity if (Lifetime > 0.5f) { ++BounceCount; } } else { DestroyProjectile(null); } }