| | | 1 | | using System; |
| | | 2 | | using UnityEngine; |
| | | 3 | | |
| | | 4 | | // The controller class is an interface between the agent and its control law. |
| | | 5 | | public class IController { |
| | | 6 | | // Agent that the controller is controlling. |
| | | 7 | | protected Agent _agent; |
| | | 8 | | |
| | 10 | 9 | | public IController(Agent agent) { |
| | 5 | 10 | | _agent = agent; |
| | 5 | 11 | | } |
| | | 12 | | |
| | | 13 | | // Plan the next optimal control to intercept the target. |
| | 0 | 14 | | public Vector3 Plan() { |
| | 0 | 15 | | Transformation relativeTransformation = |
| | | 16 | | _agent.GetRelativeTransformation(_agent.GetTargetModel()); |
| | 0 | 17 | | return PlanImpl(relativeTransformation); |
| | 0 | 18 | | } |
| | | 19 | | |
| | | 20 | | // Plan the next optimal control to the waypoint. |
| | 5 | 21 | | public Vector3 PlanToWaypoint(Vector3 waypoint) { |
| | 5 | 22 | | Transformation relativeTransformation = _agent.GetRelativeTransformationToWaypoint(waypoint); |
| | 5 | 23 | | return PlanImpl(relativeTransformation); |
| | 5 | 24 | | } |
| | | 25 | | |
| | | 26 | | // Controller-dependent implementation of the control law. |
| | 0 | 27 | | protected virtual Vector3 PlanImpl(in Transformation relativeTransformation) { |
| | 0 | 28 | | return Vector3.zero; |
| | 0 | 29 | | } |
| | | 30 | | } |