Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Update()
- {
- if (!in_valid_game_state) return;
- if (!menu_open) return;
- var vessel = GameManager.Instance.Game.ViewController.GetActiveSimVessel(true);
- // "left"??? it somehow spin-stabilizes direction during warp, lol
- // "up" only works for ~90 degrees of orbit
- // And "forward", the most expected thing, rotates 90 degrees up from targ_forward. But unlike "up" it doesn't glich out after a while
- // Makes me question if I actually know linear algebra... But prob just bad naming of methods
- var curr_forward = vessel.transform.left;
- var autopilot = vessel.Autopilot;
- var telemetry = (TelemetryComponent)autopilot.GetType().GetField("_telemetry", BindingFlags.Instance|BindingFlags.NonPublic).GetValue(autopilot);
- Vector targ_forward;
- switch (autopilot.AutopilotMode)
- {
- case AutopilotMode.StabilityAssist:
- case AutopilotMode.Maneuver:
- return;
- case AutopilotMode.Prograde:
- targ_forward = telemetry.OrbitMovementPrograde;
- break;
- case AutopilotMode.Retrograde:
- targ_forward = telemetry.OrbitMovementRetrograde;
- break;
- case AutopilotMode.Normal:
- targ_forward = telemetry.OrbitMovementNormal;
- break;
- case AutopilotMode.Antinormal:
- targ_forward = telemetry.OrbitMovementAntiNormal;
- break;
- case AutopilotMode.RadialIn:
- targ_forward = telemetry.OrbitMovementRadialIn;
- break;
- case AutopilotMode.RadialOut:
- targ_forward = telemetry.OrbitMovementRadialOut;
- break;
- case AutopilotMode.Target:
- targ_forward = telemetry.TargetDirection;
- break;
- case AutopilotMode.AntiTarget:
- targ_forward = telemetry.AntiTargetDirection;
- break;
- //TODO What are these?
- //case AutopilotMode.Navigation:
- // break;
- //case AutopilotMode.Autopilot:
- // break;
- default:
- throw new NotImplementedException(autopilot.AutopilotMode.ToString());
- }
- //Logger.LogDebug($"Vector diff sqr mag={(curr_forward - targ_forward).sqrMagnitude}");
- //if ((curr_forward - targ_forward).sqrMagnitude==0) return; //TODO <0.01
- // I would expect .FromTo to do the thing
- // But besides rotating the craft, it also makes camera wonky
- // And .LookRotation just doesn't do that
- //var rotation = Rotation.FromTo(curr_forward, targ_forward);
- var rotation = Rotation.LookRotation(curr_forward, targ_forward);
- //Logger.LogDebug($"Rotating from forward={curr_forward.vector}");
- //Logger.LogDebug($"Towards prograde={curr_forward.coordinateSystem.ToLocalVector(targ_forward)}");
- //Logger.LogDebug($"Using rotation={rotation.localRotation}");
- vessel.transform.UpdateRotation(rotation);
- }
Advertisement
Add Comment
Please, Sign In to add comment