Beispiel #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();
        }
Beispiel #2
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);
            }
        }