Esempio n. 1
0
        /// <summary>
        /// Initializing the tracer data.
        /// </summary>
        /// <param name="a_tracer">What tracerFX is it?</param>
        /// <param name="a_start">Tracer origin</param>
        /// <param name="a_end">Tracer finish</param>
        /// <param name="a_data">Data to reflect tracer</param>
        public void Init(TracerFX a_tracer, Vector3 a_start, Vector3 a_end, BulletData a_data)
        {
            speed       = a_tracer._tracerSpeed * a_tracer._tracerSpeed;
            start       = a_start;
            end         = a_end;
            impactFX    = a_tracer._impactFX;
            impactTimer = a_tracer._impactDestroyTimer;
            data        = a_data;

            particleSys = GetComponent <ParticleSystem>();
        }
Esempio n. 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);
        }
        /// <summary>
        /// Creating a particle tracer which also reflects damage depending on how its setup.
        /// </summary>
        /// <param name="a_position">Origin of the tracer</param>
        /// <param name="a_rotation">Rotational origin of the tracer</param>
        /// <param name="a_start">Where did it start? (usually the origin)</param>
        /// <param name="a_end">Where will it end?</param>
        /// <param name="a_data">Bullet data to reflect tracer</param>
        /// <returns></returns>
        public Tracer CreateTracer(Vector3 a_position, Quaternion a_rotation, Vector3 a_start, Vector3 a_end, BulletData a_data)
        {
            GameObject obj = Instantiate(_particleTracer, a_position, a_rotation, null);

            Tracer instance = obj.GetComponent <Tracer>();

            instance.Init(this, a_start, a_end, a_data);

            return(instance);
        }
Esempio n. 4
0
 /// <summary>
 /// Initiating a bullet and shooting it with respected effects.
 /// </summary>
 /// <param name="a_bulletData">A simplified data version of the original.</param>
 /// <returns>Returns the bullet hit as its shot using raycast.</returns>
 public static RaycastHit Initiate(BulletData a_bulletData)
 {
     return(Initiate(a_bulletData.origin, a_bulletData.direction, a_bulletData.spread, a_bulletData.force, a_bulletData.damage, a_bulletData.penetration, a_bulletData.tracer, a_bulletData.filter));
 }