This commit is contained in:
MrTorex committed 2026-02-06 09:49:32 +03:00
1 parent feaf2bddd0
commit bcc8782a99
42 files changed
+128 -1139

No files matched your search

+60
View File
@@ -0,0 +1,60 @@
using UnityEngine;
namespace Code.Base
{
public class Agent : MonoBehaviour
{
public float maxSpeed;
public float maxAcceleration;
public float orientation;
public float rotation;
public Vector3 velocity;
protected Steering Steering;
void Start()
{
velocity = Vector3.zero;
Steering = new Steering();
}
public void SetSteering(Steering steering) => Steering = steering;
public virtual void Update()
{
var displacement = velocity * Time.deltaTime;
orientation += rotation * Time.deltaTime;
switch (orientation)
{
case < 0:
orientation += 360;
break;
case > 360:
orientation -= 360;
break;
}
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.Normalize();
velocity *= maxSpeed;
}
if (Steering.Angular == 0) rotation = 0;
if (Steering.Linear.sqrMagnitude == 0) velocity = Vector3.zero;
Steering = new Steering();
}
}
}