BloodAndGore/Assets/Scripts/AI/Behaviours/Follow.cs

29 lines
874 B
C#
Raw Normal View History

2019-08-03 17:36:17 +02:00
using UnityEngine;
namespace Saltosion.OneWeapon.AI.Behaviours {
2019-08-04 15:44:44 +02:00
public class Follow : AIBehaviour {
2019-08-03 17:36:17 +02:00
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;
}
}
}