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

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();
// (создание нового объекта каждый кадр приведет к утечке памяти и сбросу данных)
}
}
}