lab1 base
This commit is contained in:
1 parent
bcc8782a99
commit
fcfa11c284
10 files changed
+142
No files matched your search
@@ -7,6 +7,11 @@ namespace Code.Base
|
||||
public GameObject target;
|
||||
protected Agent Agent;
|
||||
|
||||
public virtual void Awake()
|
||||
{
|
||||
Agent = GetComponent<Agent>();
|
||||
}
|
||||
|
||||
public virtual void Update()
|
||||
{
|
||||
Agent.SetSteering(GetSteering());
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7cf9369a03c4325914d2dd923ef315f
|
||||
timeCreated: 1770360608
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ca3f96f0e3e4d4689a7fd323f40553c
|
||||
timeCreated: 1770361482
|
||||
@@ -0,0 +1,19 @@
|
||||
using Code.Base;
|
||||
|
||||
namespace Code.Lab1
|
||||
{
|
||||
public class Flee : AgentBehaviour
|
||||
{
|
||||
public override Steering GetSteering()
|
||||
{
|
||||
var steering = new Steering
|
||||
{
|
||||
Linear = transform.position - target.transform.position
|
||||
};
|
||||
|
||||
steering.Linear.Normalize();
|
||||
steering.Linear *= Agent.maxAcceleration;
|
||||
return steering;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4548b6a916c440b8868ad33fe6f7ace
|
||||
timeCreated: 1770360860
|
||||
@@ -0,0 +1,42 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ec8d34239cc41588d59d9fc17112c25
|
||||
timeCreated: 1770361071
|
||||
@@ -0,0 +1,19 @@
|
||||
using Code.Base;
|
||||
|
||||
namespace Code.Lab1
|
||||
{
|
||||
public class Seek : AgentBehaviour
|
||||
{
|
||||
public override Steering GetSteering()
|
||||
{
|
||||
var steering = new Steering
|
||||
{
|
||||
Linear = target.transform.position - transform.position
|
||||
};
|
||||
|
||||
steering.Linear.Normalize();
|
||||
steering.Linear *= Agent.maxAcceleration;
|
||||
return steering;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a8ff81d84dc54a1fa40f2ebff39c9ef6
|
||||
timeCreated: 1770360733
|
||||
Reference in new issue
Block a user