27 lines
715 B
C#
27 lines
715 B
C#
using UnityEngine;
|
|
|
|
public class ViewAlignmentDetector
|
|
{
|
|
private readonly Transform _observer;
|
|
private readonly Transform _target;
|
|
|
|
public float positionErrorMargin = 1.0f;
|
|
public float viewErrorMargin = 10.0f;
|
|
|
|
public ViewAlignmentDetector(Transform observer, Transform target)
|
|
{
|
|
_observer = observer;
|
|
_target = target;
|
|
}
|
|
|
|
public bool IsAligned()
|
|
{
|
|
float dist = Vector3.Distance(_observer.position, _target.position);
|
|
bool positionMatch = dist <= positionErrorMargin;
|
|
|
|
float angle = Vector3.Angle(_observer.forward, _target.forward);
|
|
bool angleMatch = angle <= viewErrorMargin;
|
|
|
|
return positionMatch && angleMatch;
|
|
}
|
|
} |