public override void Scanning(List <ITarget> Targets, Transform obj, ISensor sensor) { DrawFieldOfView(obj, size.x, false); targetInRadius.Clear(); sensor.FilSucces.Clear(); Targets.Clear(); Collider2D[] coll = Physics2D.OverlapBoxAll(obj.position, size / 2, angleTemp); if (coll != null) { for (int i = 0; i < coll.Length; i++) { Transform other = coll[i].transform; Vector2 dirPlayer = (other.position - obj.position).normalized; if (obj.GetComponent <Sensor2D>().lastdirection == 1) { angleTemp = viewAngle; if (Vector2.Angle(obj.position, dirPlayer) < angleTemp / 2) { float distancePlayer = Vector2.Distance(obj.position, other.position); if (!Physics2D.Raycast(obj.position, dirPlayer, distancePlayer, obstacleMask)) { targetInRadius.Add(other.GetComponent <Transform>()); Targets.Add(other.GetComponent <ITarget>()); sensor.Filtering(); } } } else { angleTemp = viewAngle + 180; if (Vector2.Angle(obj.position, dirPlayer) > angleTemp / 2) { float distancePlayer = Vector2.Distance(obj.position, other.position); if (!Physics2D.Raycast(obj.position, dirPlayer, distancePlayer, obstacleMask)) { targetInRadius.Add(other.GetComponent <Transform>()); Targets.Add(other.GetComponent <ITarget>()); sensor.Filtering(); } } } } } base.Scanning(Targets, obj, sensor); }
public override void Scanning(List <ITarget> Targets, Transform obj, ISensor sensor) { DrawFieldOfView(obj, radius, true); targetInRadius.Clear(); sensor.FilSucces.Clear(); Targets.Clear(); float stepAngleSize = 360 / lines; for (int i = 0; i <= lines; i++) { float angle = obj.eulerAngles.y - viewAngle / 2 + stepAngleSize * i; RaycastHit hit; bool hits = Physics.Linecast(TopPosititon(obj) + DirFromAngle(angle, true, obj, true), BottomPosititon(obj) + DirFromAngle(angle, true, obj, true), out hit); if (hits != false) { Vector3 dirPlayer = (hit.collider.gameObject.GetComponent <Transform>().position - obj.position).normalized; if (Vector3.Angle(obj.forward, dirPlayer) < viewAngle / 2) { if (hits == true) { Debug.Log(hit); targetInRadius.Add(hit.collider.gameObject.GetComponent <Transform>()); Targets.Add(hit.collider.gameObject.GetComponent <ITarget>()); sensor.Filtering(); } } } } base.Scanning(Targets, obj, sensor); }
public override void Scanning(List <ITarget> Targets, Transform obj, ISensor sensor) { DrawFieldOfView(obj, size.x, true); targetInRadius.Clear(); sensor.FilSucces.Clear(); Targets.Clear(); Collider[] coll = Physics.OverlapBox(obj.position, size / 2); if (coll != null) { for (int i = 0; i < coll.Length; i++) { Transform other = coll[i].transform; Vector3 dirPlayer = (other.position - obj.position).normalized; if (Vector3.Angle(obj.forward, dirPlayer) < viewAngle / 2) { float distancePlayer = Vector3.Distance(obj.position, other.position); if (!Physics.Raycast(obj.position, size, distancePlayer, obstacleMask)) { targetInRadius.Add(other.GetComponent <Transform>()); Targets.Add(other.GetComponent <ITarget>()); sensor.Filtering(); } } } } base.Scanning(Targets, obj, sensor); }