Fix GetClosestTo bug(?)

This commit is contained in:
Jens Pitkänen 2019-08-15 01:26:56 +03:00
parent cc360b3932
commit ae54f85722

View File

@ -7,8 +7,7 @@ namespace Saltosion.OneWeapon.Utils {
float LowestDistance = float.PositiveInfinity; float LowestDistance = float.PositiveInfinity;
T FoundTarget = null; T FoundTarget = null;
foreach (Collider2D Collider in NearbyColliders) { foreach (Collider2D Collider in NearbyColliders) {
if (Collider.gameObject == Searcher.gameObject || if (Collider.gameObject == Searcher.gameObject) {
(Collider.attachedRigidbody != null && Collider.attachedRigidbody.gameObject == Searcher.gameObject)) {
continue; continue;
} }
@ -21,7 +20,8 @@ namespace Saltosion.OneWeapon.Utils {
if (needsLineOfSight) { if (needsLineOfSight) {
LineOfSightObstructed = false; LineOfSightObstructed = false;
foreach (RaycastHit2D Hit in Hits) { foreach (RaycastHit2D Hit in Hits) {
if (Hit.collider != Collider && Hit.transform != Searcher) { if (Hit.collider != Collider && Hit.transform != Searcher &&
(Hit.rigidbody == null || Hit.rigidbody.transform != Searcher)) {
// Hit something between the target and the searcher // Hit something between the target and the searcher
LineOfSightObstructed = true; LineOfSightObstructed = true;
break; break;