| | | 1 | | using UnityEngine; |
| | | 2 | | |
| | | 3 | | // The linear extrapolator class predicts the trajectory of an agent by linearly extrapolating its |
| | | 4 | | // current position and velocity. |
| | | 5 | | public class LinearExtrapolator : PredictorBase { |
| | 27 | 6 | | public LinearExtrapolator(IHierarchical hierarchical) : base(hierarchical) {} |
| | | 7 | | |
| | | 8 | | // Predict the future state of the hierarchical object by linearly extrapolating its current |
| | | 9 | | // position and velocity. |
| | 20 | 10 | | public override PredictorState Predict(float time) { |
| | 20 | 11 | | if (Hierarchical == null) { |
| | 0 | 12 | | return new PredictorState(); |
| | | 13 | | } |
| | | 14 | | |
| | 20 | 15 | | Vector3 position = Hierarchical.Position + Hierarchical.Velocity * time; |
| | 20 | 16 | | return new PredictorState { |
| | | 17 | | Position = position, |
| | | 18 | | Velocity = Hierarchical.Velocity, |
| | | 19 | | Acceleration = Hierarchical.Acceleration, |
| | | 20 | | }; |
| | 20 | 21 | | } |
| | | 22 | | } |