L2SE4UCTEU4R7JSHG2J5H6RZPRN4SGBMXK3WCRED2HARX5JEN2AQC
6TAXWREAGU2AW2MHM447UBAE6FNJFTBEGHZCAMVYRI4RKAODDLIQC
DGUHVA7XX4HWCIXCARJCI7T6VTXEJUOPUYZOLDOOOWIZYFEJQYFQC
R6RQ2RKQV3YFYIRN5JED6NAFB4E34WQJRDHHKZ4JO7KLBXRKNFYAC
R475KN7MR3OG7EBLVNOO7QRIKXDGY2PIDXXV3HW4KBD5QM7B5OJQC
FNS4LRFQNFM4BCB23CYHOWA2N4MG2DEUMNK6D55BQ26TX6OJLIBQC
426KOWJWOX7ZE24UIJCIHRI5KUZYO6NIGK7KC2HOONFDX242UYIQC
DTKCWM4J7PFNWAAES3RZHQGDA6PTDNX4TZVOXAKF5V7LCZBI3XUAC
62S5AKAC5VGAT4KZYRO4R6XIHO4CCD3RAUHQSW47VEGVEBNZGTGAC
OD77QV5KZG5MS7WJB6ZBNKPIODOKD4EWS6RBD3YFWJOHOAAWCL3QC
2RUZ7TTRT7SMZT2V7YWUCCTJJXNRT2LNJ2QBBVN4RMREMOGMGMHQC
public Mesh CreateArcMesh(Vector3 direction, float arc, float length, int numberOfVerticesInArc, Vector3 rotationAxis) {
public static Mesh CreateArcMesh(Vector3 direction, float arc, float length, int numberOfVerticesInArc, Vector3 rotationAxis) {
data.Affected = areaOfEffect.GetAffectedUnits(context.EffectLocation);
// Copy the location of the effect and merge with the direction caster -> target
GameObject tmpGo = new ();
tmpGo.transform.position = context.EffectLocation.position;
tmpGo.transform.rotation = direction;
data.Affected = areaOfEffect.GetAffectedUnits(tmpGo.transform);
GameObject.Destroy(tmpGo);
RaycastHit[] hits = Physics.SphereCastAll(origin.position, Radius, origin.forward, 0, LayerMask.NameToLayer("units"));
RaycastHit[] possibleHits = Physics.SphereCastAll(origin.position, Radius, origin.forward, 0, LayerMask.NameToLayer("units"));
if (possibleHits.Length == 0) {
return Enumerable.Empty<Transform>();
}
foreach (var h in possibleHits) {
Debug.Log($"ConeArea:GetAffectedUnits possbile hit: {h.transform.gameObject}");
}
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));
return hits.Select(x => x.transform).Where(unit => {
var angleBetween = origin.eulerAngles.z - unit.eulerAngles.z;
// TODO: need to check calculation
// Angle = 50 => 180 - Angle = 130
// angle = 40 => 180 - angle = 140
return (Angle <= angleBetween || 180 - angleBetween <= 180 - Angle);
});
Debug.Log($"ConeArea:GetAffectedUnits {hits.Count()} units found");
foreach (var h in hits) {
Debug.Log($"ConeArea:GetAffectedUnits hit: {h.transform.gameObject}");
}
return hits.Select(x => x.transform);
RaycastHit[] hits = Physics.SphereCastAll(origin.position, Width, origin.forward, Length, LayerMask.NameToLayer("units"));
// Get potential collisions
RaycastHit[] possibleHits = Physics.SphereCastAll(origin.position, Width, origin.forward, 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");
foreach (var h in hits) {
Debug.Log($"PathArea:GetAffectedUnits hit: {h.transform.gameObject}");
}