F6P3X2CWO6LA5VH5U64XMPQXIKA3FMDK5MFSKZJFJTFISAL7WKMQC
Mesh mesh = EffectSystem.CreateArcMesh(origin.forward, Angle, Radius, 100, Vector3.up);
MeshCollider meshCollider = origin.gameObject.AddComponent<MeshCollider>();
meshCollider.sharedMesh = mesh;
meshCollider.convex = true;
meshCollider.isTrigger = true;
//calculate exact collisions
var direction = new Vector3();
var hits = possibleHits.Where(ph => Physics.ComputePenetration(meshCollider, origin.position, origin.rotation, ph.collider, ph.transform.position, ph.transform.rotation, out direction, out float distance));
var hits = possibleHits.Where(h => {
var targetDir = (h.transform.position - origin.position).normalized;
var targetAngle = Math.Abs(Vector3.Angle(targetDir, origin.forward));
Debug.Log($"ConeArea:GetAffectedUnits target: {h.transform.gameObject} angle: {targetAngle}");
RaycastHit[] possibleHits = Physics.SphereCastAll(origin.position, Width, origin.forward, Length, LayerMask.NameToLayer("units"));
var hits = Physics.BoxCastAll(origin.position, new Vector3(Width/2, 0 , 0), origin.forward, origin.rotation, Length, LayerMask.NameToLayer("units"));
if (possibleHits.Length == 0) {
return Enumerable.Empty<Transform>();
}
Mesh mesh = EffectSystem.CreateQuadMesh(origin.forward, Width, Length, Vector3.up);
MeshCollider meshCollider = origin.gameObject.AddComponent<MeshCollider>();
meshCollider.sharedMesh = mesh;
meshCollider.convex = true;
meshCollider.isTrigger = true;
//calculate exact collisions
var direction = new Vector3();
var hits = possibleHits.Where(ph => Physics.ComputePenetration(meshCollider, origin.position, origin.rotation, ph.collider, ph.transform.position, ph.transform.rotation, out direction, out float distance));
Debug.Log($"PathArea:GetAffectedUnits {hits.Count()} units found");