10 [Header(
"Settings")] [SerializeField] [Range(1.0f, 100.0f)]
11 private float _speedMove = 10.0f;
13 [SerializeField] [Range(1.0f, 100.0f)]
private float _speedRotate = 50.0f;
15 [SerializeField]
private Vector3 _offset =
new Vector3(0.0f, 0.5f, 0.0f);
17 [SerializeField]
private float _rayCastDistance = 1.0f;
19 private readonly
bool _stop =
false;
20 private Vector3 _position;
21 private Quaternion _rotation;
31 private Vector3 Position
35 _position = transform.position - _offset;
42 transform.position = _position + _offset;
46 private Quaternion Rotation
50 _rotation = transform.rotation;
57 transform.rotation = _rotation;
65 private void OnTriggerExit(Collider other)
67 if (!other.CompareTag(
"Obstacle"))
return;
69 var obstacle = other.GetComponent<Obstacle>();
70 obstacle.PathIsBusy =
false;
73 private void OnTriggerEnter(Collider other)
75 if (!other.CompareTag(
"Obstacle"))
return;
77 var obstacle = other.GetComponent<Obstacle>();
78 obstacle.PathIsBusy =
true;
81 private void OnDrawGizmos()
83 Gizmos.color =
Color.magenta;
84 Gizmos.DrawRay(transform.position, transform.forward * (_rayCastDistance + transform.localScale.z));
89 #region PUBLIC_METHODS
91 public void Move(Vector3 currentPoint)
95 var targetLookRotation = currentPoint - Position;
97 if (targetLookRotation != Vector3.zero)
98 Rotation = Quaternion.Lerp(
100 Quaternion.LookRotation(
lookAt.transform.position - Position, Vector3.up),
101 _speedRotate * Time.deltaTime);
103 Position = Vector3.MoveTowards(
106 _speedMove * Time.deltaTime);
108 if (Vector3.Distance(Position, currentPoint) <= 0.1f)
OnEndOfRoad?.Invoke();
void Move(Vector3 currentPoint)