Skip to content

Fix #224 and implement #201. #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions VesselTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public override object GetSuffix(string suffixName)
if (suffixName == "AIRSPEED") return (target.orbit.GetVel() - FlightGlobals.currentMainBody.getRFrmVel(target.GetWorldPos3D())).magnitude; //the velocity of the vessel relative to the air);
if (suffixName == "VESSELNAME") return target.vesselName;
if (suffixName == "ALTITUDE") return target.altitude;
if (suffixName == "ALTRADAR") return target.heightFromTerrain > 0 ? Math.Min((double)target.heightFromTerrain, target.altitude) : target.altitude;
if (suffixName == "APOAPSIS") return target.orbit.ApA;
if (suffixName == "PERIAPSIS") return target.orbit.PeA;
if (suffixName == "SENSOR") return new VesselSensors(target);
Expand Down
10 changes: 9 additions & 1 deletion VesselUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ public static float GetVelocityHeading(Vessel vessel)

public static float GetTargetBearing(Vessel vessel, Vessel target)
{
if (vessel == target)
{
return 0;
}
return AngleDelta(GetHeading(vessel), GetTargetHeading(vessel, target));
}

Expand All @@ -242,8 +246,12 @@ public static float GetTargetHeading(Vessel vessel, Vessel target)
var up = vessel.upAxis;
var north = GetNorthVector(vessel);
var vector = Vector3d.Exclude(vessel.upAxis, target.GetWorldPos3D() - vessel.GetWorldPos3D()).normalized;
var headingQ = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(Quaternion.LookRotation(vector, up)) * Quaternion.LookRotation(north, up));

var headingQ = Quaternion.Inverse(Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(Quaternion.LookRotation(vector, up)) * Quaternion.LookRotation(north, up));
if(vessel == target)
{
return GetHeading(vessel);
}
return headingQ.eulerAngles.y;
}

Expand Down