29 lines
872 B
C#
29 lines
872 B
C#
using UnityEngine;
|
|
|
|
namespace Saltosion.OneWeapon.AI.Behaviours {
|
|
public class Follow : Behaviour {
|
|
public Transform Target;
|
|
public float CloseEnoughRadius;
|
|
|
|
public override bool CanBehave(Enemy subject) {
|
|
return true;
|
|
}
|
|
|
|
public override bool Execute(Enemy subject) {
|
|
if (Target != null) {
|
|
Vector2 position = subject.transform.position;
|
|
Vector2 targetPosition = Target.position;
|
|
Vector2 delta = targetPosition - position;
|
|
if (delta.magnitude > CloseEnoughRadius) {
|
|
delta -= delta.normalized * CloseEnoughRadius;
|
|
subject.StartMovingTo(position + delta);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
subject.StopMoving();
|
|
return false;
|
|
}
|
|
}
|
|
}
|