Advertisement
sumguytwitches

fast approach

Aug 11th, 2022 (edited)
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. // !runscript Z9qzkF1G
  2.  
  3.  
  4. set cam to addons:camera:flightcamera.
  5. set camflag to true.
  6. set cam:mode to "orbital".
  7. set cx to 0.
  8. set cy to -25.
  9. set cz to 0.
  10. set cd to cam:distance.
  11.  
  12.  
  13.  
  14.  
  15. set turntime to 45.
  16.  
  17. set maxapproach to ship:deltav:vacuum/2.1.
  18. set distmargin to ship:bounds:size:mag * 2.
  19.  
  20.  
  21.  
  22.  
  23. set relvel to ship:velocity:orbit - target:velocity:orbit.
  24. set tarVel to target:position:normalized.
  25.  
  26. lock steering to tarVel - relvel.
  27. lock throttle to choose (steering:mag + 2) / 2 if steering:mag > 0.01 and vang(steering,ship:facing:vector) < 5 else 0.
  28.  
  29. when true then {
  30.  
  31. set relvel to ship:velocity:orbit - target:velocity:orbit.
  32. set turnmargin to max(0,abs(vang(ship:facing:vector,-relvel) / 180)*(relvel:mag*turntime)).
  33. set rawtarSpeed to min(
  34. maxapproach,
  35. sqrt(max(0,
  36. (
  37. target:distance - turnmargin - distmargin
  38. )*2*(ship:availablethrust/ship:mass)
  39. ))
  40. ).
  41. set tarSpeed to choose rawtarspeed if rawtarspeed - relvel:mag > 10 else min(rawtarSpeed, relvel:mag).
  42. set tarspeed to choose 0 if target:distance < 200 else tarSpeed.
  43. set tarVel to target:position:normalized * tarSpeed.
  44.  
  45. if camflag { set cam:position to (-target:position:normalized*cd)*r(cx,cy,cz). }
  46.  
  47. return true.
  48. }
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56. when target:loaded then set distmargin to (ship:bounds:size:mag + target:bounds:size:mag).
  57.  
  58.  
  59. set sgp to 0.
  60. set sggo to true.
  61. set sgf to 8.
  62. set sgpr to 4.
  63. function sgd {
  64. parameter l. parameter d.
  65. If l:length > sgpr set sgpr to l:length.
  66. print (l:padleft(sgpr) + ": " +round(d,2)):padright(terminal:width) at (0, sgp).
  67. set sgp to sgp + 1.
  68. }.
  69. set sggo to false. wait 1. set sggo to true.
  70. On round(kuniverse:realtime * sgf) {
  71. set sgp to 0.
  72.  
  73. sgd("Relvel:mag",Relvel:mag).
  74. sgd("rawtarSpeed",rawtarSpeed).
  75. sgd("tarSpeed",tarSpeed).
  76. sgd("turnmargin",turnmargin).
  77. sgd("tarVel:mag",tarVel:mag).
  78. sgd("distmargin",distmargin).
  79.  
  80. Print "":padright(terminal:width) at (0,sgp).
  81. return sggo.
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement