Skip to content

Instantly share code, notes, and snippets.

@numberlesstim
Created August 12, 2024 14:14
Show Gist options
  • Select an option

  • Save numberlesstim/e03286436ccae0c7511bdfc6c8af19db to your computer and use it in GitHub Desktop.

Select an option

Save numberlesstim/e03286436ccae0c7511bdfc6c8af19db to your computer and use it in GitHub Desktop.
//gist e03286436ccae0c7511bdfc6c8af19db
parameter tarAlt.
set warp to 1.
local tx is time:seconds.
if tarAlt <= periapsis {
print "Warping to periapsis".
set tx to time:seconds + eta:periapsis.
}
else if apoapsis > 0 and tarAlt >= apoapsis {
print "Warping to apoapsis".
set tx to time:seconds + eta:apoapsis.
}
else {
if altitude > tarAlt {
local step is eta:periapsis.
if verticalspeed > 0 {
set tx to time:seconds + eta:apoapsis.
set step to step - eta:apoapsis.
}
until step < 1e-3 {
set tx to tx + step.
if
(obt:hasnextpatch and time:seconds + eta:transition < tx)
OR (obt:eccentricity < 1 and time:seconds + obt:period < tx)
OR (positionat(ship, tx) - body:position):mag - body:radius < tarAlt
{
set tx to tx - step.
set step to step/2.
}
}
}
else {
local step is eta:apoapsis.
if orbit:hasnextpatch set step to eta:transition.
if verticalspeed < 0 {
set tx to time:seconds + eta:periapsis.
set step to step - eta:periapsis.
}
until step < 1e-3 {
set tx to tx + step.
if
(obt:hasnextpatch and time:seconds + eta:transition < tx)
OR (obt:eccentricity < 1 and time:seconds + obt:period < tx)
OR (positionat(ship, tx) - body:position):mag - body:radius > tarAlt
{
set tx to tx - step.
set step to step/2.
}
}
}
}
wait until kuniverse:timewarp:issettled.
warpto(tx).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment