< Summary

Class:WaypointController
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Controller/WaypointController.cs
Covered lines:14
Uncovered lines:0
Coverable lines:14
Total lines:30
Line coverage:100% (14 of 14)
Covered branches:0
Total branches:0
Covered methods:2
Total methods:2
Method coverage:100% (2 of 2)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
WaypointController(...)0%110100%
Plan(...)0%330100%

File(s)

/github/workspace/Assets/Scripts/Controller/WaypointController.cs

#LineLine coverage
 1using UnityEngine;
 2
 3// The waypoint controller steers the agent to the target using direct linear guidance.
 4public class WaypointController : ControllerBase {
 5  // To prevent overshooting near the waypoint, if the distance to the waypoint is less than the
 6  // threshold, do not apply any acceleration.
 7  private const float _accelerationCutoffDistance = 1.0f;
 8
 189  public WaypointController(IAgent agent) : base(agent) {}
 10
 11  // Controller-dependent implementation of the control law.
 812  protected override Vector3 Plan(in Transformation relativeTransformation) {
 813    Vector3 relativePosition = relativeTransformation.Position.Cartesian;
 914    if (relativeTransformation.Position.Range < _accelerationCutoffDistance) {
 115      return Vector3.zero;
 16    }
 17
 18    // To reach the waypoint as fast as possible, use the maximum forward acceleration.
 719    Vector3 forward = Agent.Forward;
 720    Vector3 forwardAccelerationInput = forward * Agent.MaxForwardAcceleration();
 821    if (Vector3.Dot(relativePosition, Agent.Velocity) < 0) {
 122      forwardAccelerationInput *= -1;
 123    }
 24
 25    // Steer as hard as possible towards the waypoint.
 726    Vector3 normalAcceleration = Vector3.ProjectOnPlane(relativePosition, forward).normalized;
 727    Vector3 normalAccelerationInput = normalAcceleration * Agent.MaxNormalAcceleration();
 728    return forwardAccelerationInput + normalAccelerationInput;
 829  }
 30}