예제 #1
0
        /// /////////////////////////////////////////////////////////
        /// Damage
        /// /////////////////////////////////////////////////////////

        // Apply damage. Return new rigid
        RayfireRigid ImpactDamage(RayfireRigid scrRigid, RaycastHit hit, Vector3 shootPos, Vector3 shootVector, Vector3 impactPoint)
        {
            // No damage or damage disabled
            if (damage == 0 || scrRigid.damage.enable == false)
            {
                return(scrRigid);
            }

            // Check for demolition TODO input collision collider if radius is 0
            bool damageDemolition = scrRigid.ApplyDamage(damage, impactPoint, radius);

            // object was not demolished
            if (damageDemolition == false)
            {
                return(scrRigid);
            }

            // Target was demolished
            if (scrRigid.HasFragments == true)
            {
                // Get new fragment target
                bool dmlHitState = Physics.Raycast(shootPos, shootVector, out hit, maxDistance, mask, QueryTriggerInteraction.Ignore);

                // Get new hit rigid
                if (dmlHitState == true)
                {
                    if (hit.collider.attachedRigidbody != null)
                    {
                        return(hit.collider.attachedRigidbody.transform.GetComponent <RayfireRigid>());
                    }

                    if (hit.collider != null)
                    {
                        return(hit.collider.transform.GetComponent <RayfireRigid>());
                    }
                }
            }

            return(null);
        }
예제 #2
0
        // Shoot over axis
        public void Shoot(Vector3 shootPosition, Vector3 shootVector)
        {
            // Set trigger state =
            QueryTriggerInteraction trigger = QueryTriggerInteraction.Ignore;

            // Get intersection collider
            RaycastHit hit;
            bool       hitState = Physics.Raycast(shootPosition, shootVector, out hit, maxDistance, mask, trigger);

            // Pos and normal info
            Vector3 impactPoint  = hit.point;
            Vector3 impactNormal = hit.normal;

            // No hits
            if (hitState == false)
            {
                return;
            }

            // Check for tag
            if (tagFilter != "Untagged" && tag != hit.transform.tag)
            {
                return;
            }

            // If mesh collider
            // int triId = hit.triangleIndex;
            // Vector3 bar = hit.barycentricCoordinate;

            // Create impact flash
            if (enableImpactFlash == true)
            {
                ImpactFlash(hit.point, hit.normal);
            }

            // Check for Rigid script
            RayfireRigid scrRigid = hit.transform.GetComponent <RayfireRigid>();

            // NO Rigid script. TODO optional add rigid script
            if (scrRigid == null)
            {
                return;
            }

            // Apply damage if enabled
            if (scrRigid.damage.enable == true)
            {
                // Check for demolition
                bool damageDemolition = scrRigid.ApplyDamage(damage, impactPoint, radius);

                // Target was demolished
                if (damageDemolition == true && scrRigid.HasFragments == true)
                {
                    // Get new fragment target
                    bool dmlHitState = Physics.Raycast(shootPosition, shootVector, out hit, maxDistance, mask, trigger);

                    // Stop. No new target TODO proceed with debris, dust, event
                    if (dmlHitState == false)
                    {
                        return;
                    }
                }
            }

            // Hit data
            impactPoint  = hit.point;
            impactNormal = hit.normal;
            // Rigidbody rb = hit.rigidbody;
            // Collider col = hit.collider;
            scrRigid = hit.transform.GetComponent <RayfireRigid>();

            // NO Rigid script.
            if (scrRigid == null)
            {
                return;
            }

            // Activation of kinematik/inactive
            List <RayfireRigid> rigidList = ActivationCheck(scrRigid, impactPoint, radius);

            // Impact hit
            ImpactHit(rigidList, impactPoint, shootVector, hit.normal);

            // Impact Debris
            ImpactDebris(scrRigid, impactPoint, impactNormal);

            // Impact Dust
            ImpactDust(scrRigid, impactPoint, impactNormal);

            // Event
            shotEvent.InvokeLocalEvent(this);
            RFShotEvent.InvokeGlobalEvent(this);
        }