protected Vector3 CalculateAGMBallisticGuidance(MissileBase missile, Vector3 targetPosition) { if (this._guidance == null) { _guidance = new BallisticGuidance(); } return(_guidance.GetDirection(this, targetPosition)); }
protected Vector3 CalculateAGMBallisticGuidance(MissileBase missile, Vector3 targetPosition) { if (this._guidance == null) { _guidance = new BallisticGuidance(); } var newDirection = this._guidance.GetDirection(this, TargetPosition, out var timeToImpact); TimeToImpact = (float)timeToImpact; return(newDirection); }
protected Vector3 CalculateAGMBallisticGuidance(MissileBase missile, Vector3 targetPosition) { //set up if (_originalDistance == float.MinValue) { _startPoint = missile.vessel.CoM; _originalDistance = Vector3.Distance(targetPosition, missile.vessel.CoM); //calculating expected apogee bases on isosceles triangle } debugString.Append($"_originalDistance: {_originalDistance}"); debugString.Append(Environment.NewLine); debugString.Append($"BallisticOverShootFactor: {BallisticOverShootFactor}"); debugString.Append(Environment.NewLine); var surfaceDistanceVector = Vector3 .Project((missile.vessel.CoM - _startPoint), (targetPosition - _startPoint).normalized); var pendingDistance = _originalDistance - surfaceDistanceVector.magnitude; debugString.Append($"pendingDistance: {pendingDistance}"); debugString.Append(Environment.NewLine); if (TimeIndex < 1) { return(missile.vessel.CoM + missile.vessel.Velocity() * 10); } Vector3 agmTarget; // Getting apoapsis if (missile.vessel.verticalSpeed > 0 && pendingDistance > _originalDistance * 0.5) { debugString.Append($"Ascending"); debugString.Append(Environment.NewLine); var freeFallTime = CalculateFreeFallTime(); debugString.Append($"freeFallTime: {freeFallTime}"); debugString.Append(Environment.NewLine); var horizontalTime = pendingDistance / missile.vessel.horizontalSrfSpeed; debugString.Append($"horizontalTime: {horizontalTime}"); debugString.Append(Environment.NewLine); if (freeFallTime >= horizontalTime) { debugString.Append($"Free fall achieved:"); debugString.Append(Environment.NewLine); missile.Throttle = 0; agmTarget = missile.vessel.CoM + missile.vessel.Velocity() * 10; } else { debugString.Append($"Free fall not achieved:"); debugString.Append(Environment.NewLine); missile.Throttle = 1; Vector3 dToTarget = targetPosition - missile.vessel.CoM; Vector3 direction = Quaternion.AngleAxis(Mathf.Clamp(missile.maxOffBoresight * 0.9f, 0, 45f), Vector3.Cross(dToTarget, VectorUtils.GetUpDirection(missile.vessel.CoM))) * dToTarget; agmTarget = missile.vessel.CoM + direction; } debugString.Append($"Throttle: {missile.Throttle}"); debugString.Append(Environment.NewLine); } else { debugString.Append($"Descending"); debugString.Append(Environment.NewLine); agmTarget = MissileGuidance.GetAirToGroundTarget(targetPosition, missile.vessel, 1.85f); if (missile is BDModularGuidance) { if (missile.vessel.InVacuum()) { agmTarget = missile.vessel.CoM + missile.vessel.Velocity() * 10; } } missile.Throttle = Mathf.Clamp((float)(missile.vessel.atmDensity * 10f), 0.01f, 1f); } return(agmTarget); }