// Shoot over axis public void Shoot(Vector3 shootPos, Vector3 shootVector) { // Event shotEvent.InvokeLocalEvent(this); RFShotEvent.InvokeGlobalEvent(this); // Get intersection collider RaycastHit hit; bool hitState = Physics.Raycast(shootPos, shootVector, out hit, maxDistance, mask, QueryTriggerInteraction.Ignore); // No hits if (hitState == false) { return; } // Check for tag if (tagFilter != untagged && CompareTag(hit.transform.tag) == false) { return; } // Pos and normal info Vector3 impactPoint = hit.point; Vector3 impactNormal = hit.normal; // If mesh collider // int triId = hit.triangleIndex; // Vector3 bar = hit.barycentricCoordinate; // Create impact flash ImpactFlash(impactPoint, impactNormal); // Get rigid from collider or rigid body RayfireRigid rigid = hit.collider.attachedRigidbody == null ? hit.collider.GetComponent <RayfireRigid>() : hit.collider.attachedRigidbody.transform.GetComponent <RayfireRigid>(); // Collider has Rigid if (rigid != null) { // Impact Debris and dust ImpactDebris(rigid, impactPoint, impactNormal); // Impact Dust ImpactDust(rigid, impactPoint, impactNormal); // Apply damage and return new demolished rigid fragment rigid = ImpactDamage(rigid, hit, shootPos, shootVector, impactPoint); } // No Rigid script. TODO impact with object without rigid. get Rigid bodies around impact radius if (rigid == null) { return; } // Impact hit to rigid bodies. Activated inactive, detach clusters ImpactHit(rigid, hit, impactPoint, shootVector); }
// 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); }