Guest User

Untitled

a guest
Jan 3rd, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1.  
  2. public void Update()
  3. {
  4. if (!in_valid_game_state) return;
  5. if (!menu_open) return;
  6.  
  7. var vessel = GameManager.Instance.Game.ViewController.GetActiveSimVessel(true);
  8. // "left"??? it somehow spin-stabilizes direction during warp, lol
  9. // "up" only works for ~90 degrees of orbit
  10. // And "forward", the most expected thing, rotates 90 degrees up from targ_forward. But unlike "up" it doesn't glich out after a while
  11. // Makes me question if I actually know linear algebra... But prob just bad naming of methods
  12. var curr_forward = vessel.transform.left;
  13.  
  14. var autopilot = vessel.Autopilot;
  15. var telemetry = (TelemetryComponent)autopilot.GetType().GetField("_telemetry", BindingFlags.Instance|BindingFlags.NonPublic).GetValue(autopilot);
  16. Vector targ_forward;
  17. switch (autopilot.AutopilotMode)
  18. {
  19. case AutopilotMode.StabilityAssist:
  20. case AutopilotMode.Maneuver:
  21. return;
  22. case AutopilotMode.Prograde:
  23. targ_forward = telemetry.OrbitMovementPrograde;
  24. break;
  25. case AutopilotMode.Retrograde:
  26. targ_forward = telemetry.OrbitMovementRetrograde;
  27. break;
  28. case AutopilotMode.Normal:
  29. targ_forward = telemetry.OrbitMovementNormal;
  30. break;
  31. case AutopilotMode.Antinormal:
  32. targ_forward = telemetry.OrbitMovementAntiNormal;
  33. break;
  34. case AutopilotMode.RadialIn:
  35. targ_forward = telemetry.OrbitMovementRadialIn;
  36. break;
  37. case AutopilotMode.RadialOut:
  38. targ_forward = telemetry.OrbitMovementRadialOut;
  39. break;
  40. case AutopilotMode.Target:
  41. targ_forward = telemetry.TargetDirection;
  42. break;
  43. case AutopilotMode.AntiTarget:
  44. targ_forward = telemetry.AntiTargetDirection;
  45. break;
  46. //TODO What are these?
  47. //case AutopilotMode.Navigation:
  48. // break;
  49. //case AutopilotMode.Autopilot:
  50. // break;
  51. default:
  52. throw new NotImplementedException(autopilot.AutopilotMode.ToString());
  53. }
  54.  
  55. //Logger.LogDebug($"Vector diff sqr mag={(curr_forward - targ_forward).sqrMagnitude}");
  56. //if ((curr_forward - targ_forward).sqrMagnitude==0) return; //TODO <0.01
  57.  
  58. // I would expect .FromTo to do the thing
  59. // But besides rotating the craft, it also makes camera wonky
  60. // And .LookRotation just doesn't do that
  61. //var rotation = Rotation.FromTo(curr_forward, targ_forward);
  62. var rotation = Rotation.LookRotation(curr_forward, targ_forward);
  63.  
  64. //Logger.LogDebug($"Rotating from forward={curr_forward.vector}");
  65. //Logger.LogDebug($"Towards prograde={curr_forward.coordinateSystem.ToLocalVector(targ_forward)}");
  66. //Logger.LogDebug($"Using rotation={rotation.localRotation}");
  67. vessel.transform.UpdateRotation(rotation);
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment