public static void Initiate(Vector3 a_shootPos, Vector3 a_shootDir, Vector3 a_spread, float a_force, float a_damage, float a_penetration, TracerFX a_tracer, LayerMask a_filter)
        {
            a_shootDir = a_shootDir + new Vector3(Random.Range(-a_spread.x, a_spread.x), Random.Range(-a_spread.y, a_spread.y), Random.Range(-a_spread.z, a_spread.z));

            RaycastHit hit;
            if (Physics.Raycast(a_shootPos, a_shootDir, out hit, 1000, a_filter))
            {
                a_tracer.CreateTracer(a_shootPos, new Quaternion(), a_shootPos, hit.point);

                Bullet.ApplyDamage(a_force, hit, a_damage);
            }
            else
            {
                a_tracer.CreateTracer(a_shootPos, new Quaternion(), a_shootPos, a_shootPos + a_shootDir * 100);
            }
        }
Exemple #2
0
        /// <summary>
        /// Initiating a bullet and shooting it with respected effects.
        /// </summary>
        /// <param name="a_shootPos">Where does the bullet start from?</param>
        /// <param name="a_shootDir">In which direction will the bullet shoot from the shoot pos?</param>
        /// <param name="a_spread">The spread which will be randomly calculated between the negative to the positive of this value.</param>
        /// <param name="a_force">How much force will the bullet apply to the hit object?</param>
        /// <param name="a_damage">How much damage will it deal if the object is damageable?</param>
        /// <param name="a_penetration">How many objects will the bullet pass through before destroying itself?</param>
        /// <param name="a_tracer">What tracer will it use?</param>
        /// <param name="a_filter">What layers will the bullet ignore?</param>
        /// <returns>Returns the bullet hit as its shot using raycast.</returns>
        public static RaycastHit Initiate(Vector3 a_shootPos, Vector3 a_shootDir, Vector3 a_spread, float a_force, float a_damage, float a_penetration = 0, TracerFX a_tracer = null, LayerMask a_filter = default, bool a_applyTracer = true)
        {
            a_shootDir += new Vector3(Random.Range(-a_spread.x, a_spread.x), Random.Range(-a_spread.y, a_spread.y), Random.Range(-a_spread.z, a_spread.z));

            // I love inline initialization <3
            BulletData data = new BulletData {
                origin      = a_shootPos,
                direction   = a_shootDir,
                spread      = a_spread,
                force       = a_force,
                damage      = a_damage,
                penetration = a_penetration,
                tracer      = a_tracer,
                filter      = a_filter
            };

            RaycastHit hit;

            if (Physics.Raycast(a_shootPos, a_shootDir, out hit, 1000, a_filter))
            {
                if (!a_applyTracer)
                {
                    Bullet.ApplyDamage(a_force, hit, a_damage);

                    if (a_penetration > 0)
                    {
                        a_penetration -= 1;

                        Bullet.Initiate(hit.point + a_shootDir * 0.5f, a_shootDir, a_spread, a_force, a_damage, a_penetration, a_tracer, a_filter, false);
                    }
                }
            }
            else
            {
                hit.point = a_shootPos + a_shootDir * 100;
            }

            if (a_applyTracer)
            {
                Tracer tracer = a_tracer.CreateTracer(a_shootPos, new Quaternion(), a_shootPos, hit.point, data);
                tracer.hit = hit;
            }

            return(hit);
        }