42 lines
1.0 KiB
C#
42 lines
1.0 KiB
C#
using UnityEngine;
|
|
using System.Collections;
|
|
|
|
namespace Code.Example.Race.Racer.AI.ID.Behaviours
|
|
{
|
|
|
|
public class Pursue : Seek
|
|
{
|
|
public float maxPrediction;
|
|
private GameObject _targetAux;
|
|
private GameObject _target;
|
|
|
|
public void Awake()
|
|
{
|
|
_targetAux = _target;
|
|
_target = new GameObject();
|
|
}
|
|
|
|
void OnDestroy()
|
|
{
|
|
Destroy(_targetAux);
|
|
}
|
|
|
|
public override Steering GetSteering(Transform targetTransform)
|
|
{
|
|
var direction = _targetAux.transform.position - transform.position;
|
|
var distance = direction.magnitude;
|
|
var speed = agent.CarRigidbody.linearVelocity.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(_target.transform);
|
|
}
|
|
}
|
|
} |