Skip to content

Commit

Permalink
fixed sensor direction on negative scales
Browse files Browse the repository at this point in the history
  • Loading branch information
DerKekser committed Jun 23, 2024
1 parent ed50045 commit 782a736
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Assets/Kekser/Sensors/RaySensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override Collider[] GetComponentsInSensor()
{
RaycastHit[] hits = Physics.RaycastAll(
transform.position,
transform.forward,
Vector3.Scale(transform.forward, transform.localScale).normalized,
_distance,
_scanLayer,
QueryTriggerInteraction.Ignore);
Expand All @@ -33,7 +33,7 @@ protected override Collider[] GetComponentsInSensor()
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
Gizmos.DrawRay(transform.position, transform.forward * _distance);
Gizmos.DrawRay(transform.position, Vector3.Scale(transform.forward, transform.localScale).normalized * _distance);
}
}
}
4 changes: 2 additions & 2 deletions Assets/Kekser/Sensors/RaySensor2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override Collider2D[] GetComponentsInSensor()
{
RaycastHit2D[] hits = Physics2D.RaycastAll(
transform.position,
transform.right,
Vector3.Scale(transform.right, transform.localScale).normalized,
_distance,
_scanLayer);

Expand All @@ -32,7 +32,7 @@ protected override Collider2D[] GetComponentsInSensor()
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
Gizmos.DrawRay(transform.position, transform.right * _distance);
Gizmos.DrawRay(transform.position, Vector3.Scale(transform.right, transform.localScale).normalized * _distance);
}
}
}
4 changes: 2 additions & 2 deletions Assets/Kekser/Sensors/ViewSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override Collider[] GetComponentsInSensor()

for (int i = hitObjects.Count - 1; i >= 0; i--)
{
if (Vector3.Angle(hitObjects[i].transform.position - transform.position, transform.forward) > _angle / 2f)
if (Vector3.Angle(hitObjects[i].transform.position - transform.position, Vector3.Scale(transform.forward, transform.localScale).normalized) > _angle / 2f)
hitObjects.RemoveAt(i);
}

Expand All @@ -31,7 +31,7 @@ protected override Collider[] GetComponentsInSensor()
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
SensorGizmos.DrawWireView(transform.position, transform.forward, _range, _angle);
SensorGizmos.DrawWireView(transform.position, Vector3.Scale(transform.forward, transform.localScale).normalized, _range, _angle);
}
}
}
4 changes: 2 additions & 2 deletions Assets/Kekser/Sensors/ViewSensor2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected override Collider2D[] GetComponentsInSensor()

for (int i = hitObjects.Count - 1; i >= 0; i--)
{
if (Vector2.Angle(hitObjects[i].transform.position - transform.position, transform.right) > _angle / 2f)
if (Vector2.Angle(hitObjects[i].transform.position - transform.position, Vector3.Scale(transform.right, transform.localScale).normalized) > _angle / 2f)
hitObjects.RemoveAt(i);
}

Expand All @@ -31,7 +31,7 @@ protected override Collider2D[] GetComponentsInSensor()
private void OnDrawGizmosSelected()
{
Gizmos.color = Color.yellow;
SensorGizmos.DrawWireView(transform.position, transform.right, _range, _angle);
SensorGizmos.DrawWireView(transform.position, Vector3.Scale(transform.right, transform.localScale).normalized, _range, _angle);
}
}
}

0 comments on commit 782a736

Please sign in to comment.