void FindVisibleTargets() { visibleTargets.Clear(); Collider2D[] targetsInViewRadius = Physics2D.OverlapCircleAll(transform.position, viewRadius, targetMask); foreach (Collider2D c in targetsInViewRadius) { // Ignore self if (c.gameObject == this.gameObject) { continue; } Transform tar = c.transform; Vector2 dirToTar = (tar.position - transform.position).normalized; float targetAngle = GameTrig.gameAngleBetweenTwoPoints(c.transform.position, gameObject.transform.position); if (GameTrig.betweenGameAngles(viewRotation + (viewAngle / 2), viewRotation - (viewAngle / 2), targetAngle)) { float disToTar = Vector2.Distance(transform.position, tar.position); if (!Physics2D.Raycast(transform.position, dirToTar, disToTar, obstacleMask)) { visibleTargets.Add(tar); } } } }
void FixedUpdate() { fov.setRotation(GameTrig.gameAngleBetweenTwoPoints(Vector2.Lerp(currentDir, targetDir, Time.fixedDeltaTime), currPos)); }