| | | 1 | | using UnityEngine; |
| | | 2 | | |
| | | 3 | | // Base implementation of a controller. |
| | | 4 | | public abstract class ControllerBase : IController { |
| | | 5 | | // Agent that the controller is steering. |
| | 150 | 6 | | public IAgent Agent { get; init; } |
| | | 7 | | |
| | 42 | 8 | | public ControllerBase(IAgent agent) { |
| | 21 | 9 | | Agent = agent; |
| | 21 | 10 | | } |
| | | 11 | | |
| | | 12 | | // Plan the next optimal control to intercept the target. |
| | 23 | 13 | | public Vector3 Plan() { |
| | 24 | 14 | | if (Agent.TargetModel == null) { |
| | 1 | 15 | | return Vector3.zero; |
| | | 16 | | } |
| | | 17 | | |
| | 22 | 18 | | Transformation relativeTransformation = Agent.GetRelativeTransformation(Agent.TargetModel); |
| | 22 | 19 | | return Plan(relativeTransformation); |
| | 23 | 20 | | } |
| | | 21 | | |
| | | 22 | | // Plan the next optimal control to the waypoint. |
| | 0 | 23 | | public Vector3 Plan(in Vector3 waypoint) { |
| | 0 | 24 | | Transformation relativeTransformation = Agent.GetRelativeTransformation(waypoint); |
| | 0 | 25 | | return Plan(relativeTransformation); |
| | 0 | 26 | | } |
| | | 27 | | |
| | | 28 | | // Controller-dependent implementation of the control law. |
| | | 29 | | protected abstract Vector3 Plan(in Transformation relativeTransformation); |
| | | 30 | | } |