コード例 #1
0
    public void CreateExplosionBlastWave(Vector3 ground_position, Vector3 normal, float delayTime = 0)
    {
        ExplosionSphere blast = Instantiate(blastHemispherePrefab, ground_position, Quaternion.LookRotation(normal)) as ExplosionSphere;

        blast.delayTime        = delayTime;
        blast.transform.parent = this.transform;
    }
コード例 #2
0
    public void CreateLingeringFireball(Vector3 position, Vector3 normal, float startTimeInSeconds)
    {
        ExplosionSphere hemisphere = Instantiate(flameHemispherePrefab, position + normal * .01f, Quaternion.LookRotation(normal)) as ExplosionSphere;

        hemisphere.delayTime        = startTimeInSeconds;
        hemisphere.transform.parent = this.transform;
    }
コード例 #3
0
    public void CreateExplosionCloud(Vector3 position, float radius, int count, float delay_time = 0)
    {
        float start_time = 0;

        while (count-- > 0)
        {
            Vector3            pos = position + RandomPosition(radius);
            ExplosionBillboard billboard_explosion  = Instantiate(m_explosion_billboard1_prefab, pos, m_explosion_billboard1_prefab.transform.rotation) as ExplosionBillboard;
            ExplosionSphere    volumetric_explosion = Instantiate(m_explosion_sphere_prefab, pos, m_explosion_sphere_prefab.transform.rotation) as ExplosionSphere;
            billboard_explosion.delayTime  = start_time;
            volumetric_explosion.delayTime = start_time;
            start_time += delay_time;
        }
    }
コード例 #4
0
    public void CreateExplosionPillar(Vector3 base_pos, float height, int count, float delay_time = 0)
    {
        float   vertical_step_size = height / count;
        Vector3 pos        = base_pos;
        float   start_time = Time.time;

        while (count-- > 0)
        {
            ExplosionBillboard billboard_explosion  = Instantiate(m_explosion_billboard1_prefab, pos, m_explosion_billboard1_prefab.transform.rotation) as ExplosionBillboard;
            ExplosionSphere    volumetric_explosion = Instantiate(m_explosion_sphere_prefab, pos, m_explosion_sphere_prefab.transform.rotation) as ExplosionSphere;
            billboard_explosion.delayTime  = start_time;
            volumetric_explosion.delayTime = start_time;
            start_time += delay_time;
            pos        += Vector3.up * vertical_step_size;
        }
    }
コード例 #5
0
    public void CreateExplosionCloud(Vector3 position, float radius, int count, float delayTime = 0)
    {
        float startTime = 0;

        while (count-- > 0)
        {
            Vector3            pos = position + RandomPosition(radius);
            ExplosionBillboard billboardExplosion  = Instantiate(explosionBillboard1Prefab, pos, explosionBillboard1Prefab.transform.rotation) as ExplosionBillboard;
            ExplosionSphere    volumetricExplosion = Instantiate(explosionSpherePrefab, pos, explosionSpherePrefab.transform.rotation) as ExplosionSphere;
            billboardExplosion.delayTime         = startTime;
            volumetricExplosion.delayTime        = startTime;
            billboardExplosion.transform.parent  = this.transform;
            volumetricExplosion.transform.parent = this.transform;
            startTime += delayTime;
        }
    }
コード例 #6
0
    public void CreateExplosionPillar(Vector3 base_pos, float height, int count, float delayTime = 0)
    {
        float   verticalStepSize = height / count;
        Vector3 pos       = base_pos;
        float   startTime = Time.time;

        while (count-- > 0)
        {
            ExplosionBillboard billboardExplosion  = Instantiate(explosionBillboard1Prefab, pos, explosionBillboard1Prefab.transform.rotation) as ExplosionBillboard;
            ExplosionSphere    volumetricExplosion = Instantiate(explosionSpherePrefab, pos, explosionSpherePrefab.transform.rotation) as ExplosionSphere;
            billboardExplosion.delayTime         = startTime;
            volumetricExplosion.delayTime        = startTime;
            billboardExplosion.transform.parent  = this.transform;
            volumetricExplosion.transform.parent = this.transform;
            startTime += delayTime;
            pos       += Vector3.up * verticalStepSize;
        }
    }
コード例 #7
0
    public void CreateBulletImpactDebris(Vector3 origin, Vector3 normal, float radius, int count, float start_time_in_seconds)
    {
        /*
         * Generate random points on the plane described by the impact position and
         * normal.
         *
         * Find two perpendicular vectors in plane to form a basis set. The second
         * is just the cross product of plane normal and first vector. The first
         * vector is any arbitrary vector parallel to plane. Equation of plane is:
         *
         *  (P-O).N = 0 -> nx*x + ny*y + nz*z - (nx*ox+ny*oy+nz*oz) = 0
         *
         * Where P = (x,y,z) is some arbitrary point on plane, O is a known point,
         * and N is the plane normal vector. Therefore:
         *
         *  a = nx, b = ny, c = nz, d = -(N.O)
         *
         * We can solve for z:
         *
         *  z = -(a*x + b*y + d) / c
         *
         * Then pick x and y to find z:
         *
         *  x = 1, y = 2, z = -(a + 2b + d) / c
         *
         * If nz = 0, just pick x and z:
         *
         *  y = -(a*x + c*z + d) / b
         *  x = 1, z = 2, y = -(a + 2*c + d) / b
         *
         * Remember that this solves for the *point*, P. To get the axis, subtract
         * O.
         */

        float   a = normal.x;
        float   b = normal.y;
        float   c = normal.z;
        float   d = -Vector3.Dot(normal, origin);
        Vector3 plane_x_axis;
        Vector3 plane_y_axis;

        if (Mathf.Abs(normal.z) < 1e-6)
        {
            if (Mathf.Abs(normal.y) < 1e-6)
            {
                // Normal along x axis, trivial to pick perpendicular axes
                plane_x_axis = new Vector3(0, 0, 1);
            }
            else
            {
                plane_x_axis = new Vector3(1, -(a + 2 * c + d) / b, 2) - origin;
            }
        }
        else
        {
            plane_x_axis = new Vector3(1, 2, -(a + 2 * b + d) / c) - origin;
        }
        plane_x_axis = Vector3.Normalize(plane_x_axis);
        plane_y_axis = Vector3.Normalize(Vector3.Cross(plane_x_axis, normal));

        const float delay_time = 0;
        float       start_time = start_time_in_seconds;

        while (count-- > 0)
        {
            Vector2         pos2d      = RandomPosition2D(radius);
            Vector3         pos        = origin + pos2d.x * plane_x_axis + pos2d.y * plane_y_axis;
            ExplosionSphere hemisphere = Instantiate(m_dust_hemisphere_prefab, pos, Quaternion.LookRotation(normal)) as ExplosionSphere;
            hemisphere.delayTime = start_time;
            start_time          += delay_time;
        }
    }
コード例 #8
0
    public void CreateLingeringFireball(Vector3 position, Vector3 normal, float start_time_in_seconds)
    {
        ExplosionSphere hemisphere = Instantiate(m_flame_hemisphere_prefab, position + normal * .01f, Quaternion.LookRotation(normal)) as ExplosionSphere;

        hemisphere.delayTime = start_time_in_seconds;
    }
コード例 #9
0
    public void CreateBulletImpactDebris(Vector3 origin, Vector3 normal, float radius, int count, float startTimeInSeconds)
    {
        /*
         * Generate random points on the plane described by the impact position and
         * normal.
         *
         * Find two perpendicular vectors in plane to form a basis set. The second
         * is just the cross product of plane normal and first vector. The first
         * vector is any arbitrary vector parallel to plane. Equation of plane is:
         *
         *  (P-O).N = 0 -> nx*x + ny*y + nz*z - (nx*ox+ny*oy+nz*oz) = 0
         *
         * Where P = (x,y,z) is some arbitrary point on plane, O is a known point,
         * and N is the plane normal vector. Therefore:
         *
         *  a = nx, b = ny, c = nz, d = -(N.O)
         *
         * We can solve for z:
         *
         *  z = -(a*x + b*y + d) / c
         *
         * Then pick x and y to find z:
         *
         *  x = 1, y = 2, z = -(a + 2b + d) / c
         *
         * If nz = 0, just pick x and z:
         *
         *  y = -(a*x + c*z + d) / b
         *  x = 1, z = 2, y = -(a + 2*c + d) / b
         *
         * Remember that this solves for the *point*, P. To get the axis, subtract
         * O.
         */

        float   a = normal.x;
        float   b = normal.y;
        float   c = normal.z;
        float   d = -Vector3.Dot(normal, origin);
        Vector3 planeXAxis;
        Vector3 planeYAxis;

        if (Mathf.Abs(normal.z) < 1e-6)
        {
            if (Mathf.Abs(normal.y) < 1e-6)
            {
                // Normal along x axis, trivial to pick perpendicular axes
                planeXAxis = new Vector3(0, 0, 1);
            }
            else
            {
                planeXAxis = new Vector3(1, -(a + 2 * c + d) / b, 2) - origin;
            }
        }
        else
        {
            planeXAxis = new Vector3(1, 2, -(a + 2 * b + d) / c) - origin;
        }
        planeXAxis = Vector3.Normalize(planeXAxis);
        planeYAxis = Vector3.Normalize(Vector3.Cross(planeXAxis, normal));

        const float delayTime = 0;
        float       startTime = startTimeInSeconds;

        while (count-- > 0)
        {
            // Spawn cloud at a random location within a circular region
            Vector2         pos2d      = RandomPosition2D(radius);
            Vector3         pos        = origin + pos2d.x * planeXAxis + pos2d.y * planeYAxis;
            ExplosionSphere hemisphere = Instantiate(dustHemispherePrefab, pos, Quaternion.LookRotation(normal)) as ExplosionSphere;
            hemisphere.delayTime        = startTime;
            hemisphere.transform.parent = this.transform;
            startTime += delayTime;

            // Launch pieces of flying debris in random directions along an outward-
            // facing hemisphere. Note that RandomPositionHemisphere() places a point
            // in a hemisphere with base in xy and axis along z (forward).
            Vector3     flyTowards = Quaternion.FromToRotation(Vector3.forward, normal) * Vector3.Normalize(RandomPositionHemisphere(radius));
            int         which      = Random.Range(0, debrisFragmentPrefabs.Length);
            TimeLimited debris     = Instantiate(debrisFragmentPrefabs[which], pos, Quaternion.identity) as TimeLimited;
            debris.transform.parent = this.transform;
            Rigidbody rb = debris.GetComponent <Rigidbody>();
            rb.maxAngularVelocity = 30;
            rb.AddForce(rb.mass * (Vector3.up + flyTowards), ForceMode.Impulse); // slightly biased toward flying upward
            rb.AddRelativeTorque(10f * rb.mass * Vector3.right, ForceMode.Impulse);
        }
    }