Files
ID/Assets/Code/Lab1/Pursue.cs
T
2026-02-06 10:06:04 +03:00

42 lines
1.1 KiB
C#

using Code.Base;
using UnityEngine;
namespace Code.Lab1
{
public class Pursue : Seek
{
public float maxPrediction;
private GameObject _targetAux;
private Agent _targetAgent;
public override void Awake()
{
base.Awake();
_targetAgent = target.GetComponent<Agent>();
_targetAux = target;
target = new GameObject();
}
private void OnDestroy()
{
Destroy(_targetAux);
}
public override Steering GetSteering()
{
var direction = _targetAux.transform.position - transform.position;
var distance = direction.magnitude;
var speed = Agent.velocity.magnitude;
float prediction;
if (speed <= distance / maxPrediction)
prediction = maxPrediction;
else
prediction = distance / speed;
target.transform.position = _targetAux.transform.position;
target.transform.position += _targetAgent.velocity * prediction;
return base.GetSteering();
}
}
}