Esempio n. 1
0
        // FinalStageShooting
        protected override void FinalStageShooting()
        {
            RaycastHit hitInfo;

            if (Physics.SphereCast(projectileOuter.position, swayRadius, projectileOuter.forward, out hitInfo, swayRange, hitMask))
            {
                Collider hitCollider = hitInfo.collider;
                if (hitCollider.isTrigger)
                {
                    return;
                }

                IDamageHandler handler = hitCollider.GetComponent <IDamageHandler>();
                if (handler != null)
                {
                    handler.TakeDamage(new DamageInfo(damage, projectileOuter.root, owner, EDamageType.Melee));
                }

                HitEffect.SpawnHitEffect(hitEffect, hitInfo);

                Rigidbody tmpRb = hitCollider.attachedRigidbody;
                if (tmpRb != null && !tmpRb.isKinematic)
                {
                    tmpRb.AddForce(projectileOuter.forward * (hitForce * 1.75f / (tmpRb.mass > 1f ? tmpRb.mass : 1f)), ForceMode.Impulse);
                }
            }

            base.FinalStageShooting();
        }
Esempio n. 2
0
        // Spawn HitEffect
        public static void SpawnHitEffect(HitEffect hitObject, RaycastHit hit, bool showHitTexture = false)
        {
            if (hit.collider == null || hit.collider.isTrigger)
            {
                return;
            }

            if (hitObject == null)
            {
                Debug.LogError("ERROR: Decal Object is not setup!");
                return;
            }

            Texture        hitTexture  = hitObject.generic.hitTexture;
            AudioClip      hitSound    = hitObject.generic.hitSound;
            ParticleSystem hitParticle = hitObject.generic.hitParticle;

            int tmpIndex = SurfaceDetector.GetSurfaceIndexByHit(hit);

            foreach (SurfaceData sur in hitObject.surfaces)
            {
                if (sur.index == tmpIndex)
                {
                    hitTexture  = sur.hitTexture;
                    hitSound    = sur.hitSound;
                    hitParticle = sur.hitParticle;
                    break;
                }
            }

            HitEffect tmpHitObject = hitObject.SpawnCopy(hit.point + hit.normal * .0003f, Quaternion.FromToRotation(Vector3.forward, hit.normal));

            tmpHitObject.Configure(showHitTexture ? hitTexture : null, hitSound, hitParticle);
            tmpHitObject.transform.SetParent(hit.transform);
        }
Esempio n. 3
0
        // Impact
        private void Impact()
        {
            movement     = false;
            nextPosition = hitInfo.point;

            if (IsExplosionObject())
            {
                return;
            }

            m_Transform.position = nextPosition;

            bool showHitTexture = (subType == EProjectileSubType.Bullet);

            IDamageHandler handler = hitInfo.collider.GetComponent <IDamageHandler>();

            if (handler != null)
            {
                handler.TakeDamage(new DamageInfo(damage, m_Transform, owner, EDamageType.Impact));
                showHitTexture = (handler.isPlayer == false && handler.isNPC == false);
            }

            HitEffect.SpawnHitEffect(decalObject, hitInfo, showHitTexture);

            Rigidbody tmpRb = hitInfo.collider.attachedRigidbody;

            if (tmpRb != null && tmpRb.isKinematic == false)
            {
                tmpRb.AddForce(m_Transform.forward * ((damage / 10f) * (damage * 20f) / 100f / (tmpRb.mass > 1f ? tmpRb.mass : 1f)), ForceMode.Impulse);
            }


            if (subType == EProjectileSubType.Arrow)
            {
                Collider tmpCollider = GetComponent <Collider>();
                if (tmpCollider == null)
                {
                    Debug.LogWarning("Collider is not found! Projectile(Arrow) has been destroyed! Warning in " + this.name);
                    Destroy(gameObject);
                    return;
                }

                tmpCollider.enabled = true;
                tmpRb = tmpCollider.attachedRigidbody;

                if (type == EProjectileType.Ballistic && tmpRb != null)
                {
                    tmpRb.velocity    = Vector3.zero;
                    tmpRb.useGravity  = false;
                    tmpRb.isKinematic = true;
                    tmpRb.Sleep();
                }

                Pickup tmpPickup = GetComponent <Pickup>();

                if (tmpPickup != null)
                {
                    tmpPickup.enabled = true;
                }

                m_Transform.SetParent(hitInfo.transform);
            }
            else
            {
                Destroy(gameObject);
            }
        }