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

+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ab0550f25a194f9f8d2d8e36ed7327bc
timeCreated: 1770359902
+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();
}
}
}
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 667192835ef34ac0ab5b96cd41821f46
timeCreated: 1770360139
+20
View File
@@ -0,0 +1,20 @@
using UnityEngine;
namespace Code.Base
{
public class AgentBehaviour : MonoBehaviour
{
public GameObject target;
protected Agent Agent;
public virtual void Update()
{
Agent.SetSteering(GetSteering());
}
public virtual Steering GetSteering()
{
return new Steering();
}
}
}
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b50ad7c7cb7145468dd7232f31b0688b
timeCreated: 1770360063
+10
View File
@@ -0,0 +1,10 @@
using UnityEngine;
namespace Code.Base
{
public class Steering
{
public float Angular = 0;
public Vector3 Linear = new();
}
}
+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5390ee0c23e044e7a6a751325ad78254
timeCreated: 1770359913