This commit is contained in:
MrTorex committed 2026-02-10 12:35:10 +03:00
1 parent a70076ebe9
commit 854835878c
20 files changed
+2542

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
using Code.Base;
using UnityEngine;
namespace Code.Lab3
{
public class Align : AgentBehaviour
{
public float targetRadius;
public float slowRadius;
public float timeToTarget = 0.1f;
public override Steering GetSteering()
{
var steering = new Steering();
var targetOrientation = target.GetComponent<Agent>().orientation;
var rotation = targetOrientation - Agent.orientation;
rotation = MapToRange(rotation);
var rotationSize = Mathf.Abs(rotation);
if (rotationSize < targetRadius)
return steering;
float targetRotation;
if (rotationSize > slowRadius)
targetRotation = Agent.maxRotation;
else
targetRotation = Agent.maxRotation * rotationSize / slowRadius;
targetRotation *= rotation / rotationSize;
steering.Angular = targetRotation - Agent.rotation;
steering.Angular /= timeToTarget;
var angularAccel = Mathf.Abs(steering.Angular);
if (!(angularAccel > Agent.maxAngularAcceleration)) return steering;
steering.Angular /= angularAccel;
steering.Angular *= Agent.maxAngularAcceleration;
return steering;
}
}
}