Advertisement
sumguytwitches

Untitled

Dec 14th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if not (defined launch_margin) declare global launch_margin is 60.
  2. if not (defined orbital_speed_multiplier) declare global orbital_speed_multiplier is 0.6.
  3. set t0 to time:seconds.
  4. set r0 to ship:position-body:position.
  5. set rh to vxcl(v(0,1,0),r0).
  6. set rv to vxcl(rh,r0).
  7. set ph to vcrs(rh,v(0,1,0)).
  8. lock t to time:seconds.
  9. function pos {parameter x. return positionat(x,t)-x:body:position.}
  10. function vel {parameter x. return velocityat(x,t):obt.}
  11. function nrm {parameter x. return vcrs(vel(x),pos(x)):normalized.}
  12. lock rs to pos(ship). lock vs to vel(ship). lock ns to nrm(ship).
  13. lock rt to pos(target). lock vt to vel(target). lock nt to nrm(target).
  14. set a to vdot(rh,nt).
  15. set b to vdot(ph,nt).
  16. set arg to -vdot(rv,nt)/sqrt(a^2+b^2).
  17. if(abs(arg) > 1) log_error("no solution").
  18. set theta1 to arccos(arg).
  19. set theta2 to 360-theta1.
  20. set q1 to mod(360+theta1+arctan2(b,a),360).
  21. set q2 to mod(360+theta2+arctan2(b,a),360).
  22. set first to min(q1,q2).
  23. set tlaunch to t0 + (first/360)*body:rotationperiod - launch_margin.
  24. print "Warping to launch window...".
  25. if time:seconds < tlaunch-300 {warpto(tlaunch-300). wait 0.}
  26. wait until warp=0 and kuniverse:timewarp:issettled and velocity:surface:mag < 0.1 and time:seconds > tlaunch-300.
  27. if time:seconds < tlaunch-10 {set warp to 1. wait until kuniverse:timewarp:issettled. warpto(tlaunch-10). wait 0.}
  28. wait until warp=0 and kuniverse:timewarp:issettled and time:seconds > tlaunch-10.
  29. print "Waiting " + round(tlaunch-time:seconds) + " seconds for launch window...".
  30. wait until warp=0 and kuniverse:timewarp:issettled and time:seconds > tlaunch - 3.
  31. function hdg {parameter x. return mod(360+arctan2(x*vcrs(up:vector,north:vector),x*north:vector),360).}
  32. set h to hdg(vcrs(rs, nt):normalized*sqrt(body:mu/(body:radius+body:atm:height+10e3))*orbital_speed_multiplier - velocity:obt).
  33. print "Launching at heading " + h.
  34. run launch_to_orbit(0, h).
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement