Начал ИД вроде

This commit is contained in:
ThomasCharester committed 2026-02-06 22:52:36 +03:00
1 parent cd56b1969c
commit f557c58c9d
35 files changed
+683 -1484

No files matched your search

@@ -0,0 +1,58 @@
using UnityEngine;
namespace Code.Example.Race.Racer.AI.ID
{
public class Agent : MonoBehaviour
{
public float maxSpeed;
public float maxAccel;
public float orientation;
public float rotation;
public Vector3 velocity;
protected Steering steering;
private void Start()
{
velocity = Vector3.zero;
steering = new Steering();
}
public void SetSteering(Steering steering)
{
this.steering = steering;
}
public virtual void Update ()
{
Vector3 displacement = velocity * Time.deltaTime;
orientation += rotation * Time.deltaTime;
// необходимо ограничить значение переменной orientation
// диапазоном (0-360)
if (orientation < 0.0f)
orientation += 360.0f;
else if (orientation > 360.0f)
orientation -= 360.0f;
transform.Translate(displacement, Space.World);
transform.rotation = new Quaternion();
transform.Rotate(Vector3.up, orientation);
}
public virtual void LateUpdate()
{
velocity += steering.linear * Time.deltaTime;
rotation += steering.angular * Time.deltaTime;
if (velocity.magnitude > maxSpeed)
{
velocity = velocity.normalized * maxSpeed; // Исправлено: корректное нормирование вектора
}
if (steering.angular == 0.0f)
{
rotation = 0.0f;
}
if (steering.linear.sqrMagnitude == 0.0f)
{
velocity = Vector3.zero;
}
// Удалена строка: steering = new Steering();
// (создание нового объекта каждый кадр приведет к утечке памяти и сбросу данных)
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6d51ddde70f34264954a75923b43dcee
timeCreated: 1770394764
@@ -0,0 +1,11 @@
using UnityEngine;
namespace Code.Example.Race.Racer.AI.ID
{
public abstract class AgentBehaviour : MonoBehaviour
{
[SerializeField] protected AIRacerID agent;
public abstract Steering GetSteering(Transform target);
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5af0fc1b61bd44d9a53fd01f93fe6029
timeCreated: 1770394682
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 70ca406222fb4e8e848ccf43db320cc9
timeCreated: 1770395746
@@ -0,0 +1,17 @@
using UnityEngine;
namespace Code.Example.Race.Racer.AI.ID.Behaviours
{
public class Flee : AgentBehaviour
{
public override Steering GetSteering(Transform target)
{
Steering steering = new Steering();
steering.linear = transform.position - target.position;
steering.linear.Normalize();
steering.linear *= agent.Data.maxAcceleration;
return steering;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 437d2ae2cd65457a82abc34df278228d
timeCreated: 1770395798
@@ -0,0 +1,17 @@
using UnityEngine;
namespace Code.Example.Race.Racer.AI.ID.Behaviours
{
public class Seek : AgentBehaviour
{
public override Steering GetSteering(Transform target)
{
Steering steering = new Steering();
steering.linear = target.position - transform.position;
steering.linear.Normalize();
steering.linear *= agent.Data.maxAcceleration;
return steering;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: aa69eb79c9ec48b682606dac0c0d4f2d
timeCreated: 1770395751
@@ -0,0 +1,16 @@
using UnityEngine;
namespace Code.Example.Race.Racer.AI.ID
{
public struct Steering
{
public float angular;
public Vector3 linear;
public Steering(float angular, Vector3 linear)
{
this.angular = angular;
this.linear = linear;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0395b595869e49b5b177fe54db531823
timeCreated: 1770394582