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().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; } } }