lab1 base
This commit is contained in:
1 parent
bcc8782a99
commit
fcfa11c284
10 files changed
+142
No files matched your search
@@ -0,0 +1,42 @@
|
||||
using Code.Base;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Code.Lab1
|
||||
{
|
||||
public class Evade : Flee
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user