public override Vector3 Track(float deltaTime) { if (emit == null) { return(Vector3.zero); } RaycastHit[] hitsInfos = Physics.RaycastAll(emit.position, emit.forward, range, GameConfig.ProjectileDamageLayer); foreach (RaycastHit hitInfo in hitsInfos) { Collider collider = hitInfo.collider; if (collider == null || collider.tag == "WorldCollider" || collider.transform.IsChildOf(transform) || m_Emitter != null && collider.transform.IsChildOf(m_Emitter)) { continue; } PEDefenceTrigger defencetrigger = collider.GetComponent <PEDefenceTrigger>(); PECapsuleHitResult result; if (null == defencetrigger && collider.isTrigger) { continue; } if (null == defencetrigger || !defencetrigger.RayCast(new Ray(emit.position, emit.forward), range, out result) || result.distance < hitInfo.distance) { m_HitPositions.Add(hitInfo.point); } else { m_HitPositions.Add(result.hitPos); } } Vector3 finalPos = emit.position + emit.forward * range; float closetDistance = 2 * range * 2 * range; for (int i = 0; i < m_HitPositions.Count; ++i) { float sqrDistance = (m_HitPositions[i] - emit.position).sqrMagnitude; if (sqrDistance < closetDistance) { closetDistance = sqrDistance; finalPos = m_HitPositions[i]; } } m_HitPositions.Clear(); return(finalPos - transform.position); }
void CheckHit() { if (null != m_Beat && Input.GetMouseButtonDown(0)) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); // Raycast to find a ragdoll collider RaycastHit hit = new RaycastHit(); if (Physics.Raycast(ray, out hit, 100f, m_CheckLayer.value)) { PEDefenceTrigger defenceTrigger = hit.collider.GetComponent <PEDefenceTrigger>(); PECapsuleHitResult result; if (defenceTrigger.RayCast(ray, 1000f, out result)) { m_Beat.Beat(GetComponentInParent <SkAliveEntity>(), result.hitTrans, ray.direction, m_HitPower); } } } }
bool GetRaycastInfo(Vector3 position, Vector3 velcity, out RaycastHit hitInfo, out Transform hitTrans, out PECapsuleHitResult hitResult, out bool useHitReslut, int layer) { hitResult = null; useHitReslut = false; hitInfo = new RaycastHit(); hitTrans = null; if (velcity.sqrMagnitude > 0.05f * 0.05f) { Ray rayStart = new Ray(position, velcity); RaycastHit[] hitInfos = Physics.RaycastAll(rayStart, velcity.magnitude, layer); hitInfos = PETools.PEUtil.SortHitInfo(hitInfos, false); RaycastHit hit; for (int i = 0; i < hitInfos.Length; ++i) { hit = hitInfos[i]; if (hit.transform == null) { continue; } if (hit.transform.IsChildOf(transform)) { continue; } if (m_Caster != null && hit.transform.IsChildOf(m_Caster)) { continue; } if (hit.collider.gameObject.tag == "EnergyShield") { EnergySheildHandler shield = hit.collider.GetComponent <EnergySheildHandler>(); if (shield != null) { shield.Impact(hit.point); } continue; } hitInfo = hit; hitTrans = hit.transform; PEDefenceTrigger defencetrigger = hit.transform.GetComponent <PEDefenceTrigger>(); if (null != defencetrigger) { if (!defencetrigger.RayCast(rayStart, 100f, out hitResult)) { continue; } hitInfo.point = hitResult.hitPos; hitTrans = hitResult.hitTrans; useHitReslut = true; } else if (hit.collider.isTrigger) { return(false); } return(true); } } return(false); }