diff --git a/lib/rendezvous.ks b/lib/rendezvous.ks deleted file mode 100644 index ecd7969..0000000 --- a/lib/rendezvous.ks +++ /dev/null @@ -1,28 +0,0 @@ -@LAZYGLOBAL off. - -run once "lib/node". - - -function relative_velocity { - // - // Return the relative orbital velocity between the ship and our target in the target's inertial frame of reference. - // - if not HASTARGET { - return V(0,0,0). // avoids 'has no target' errors upon docking - } - - local t is TARGET. - if TARGET:istype("Part") { // e.g. if selected docking port as target - set t to TARGET:ship. - } - return SHIP:velocity:orbit - t:velocity:orbit. -} - - -function kill_relative_velocity { - parameter tolerance is 0.1. - - if relative_velocity():mag > tolerance { - execute_burn(-relative_velocity()). - } -} diff --git a/lib/target.ks b/lib/target.ks new file mode 100644 index 0000000..608da08 --- /dev/null +++ b/lib/target.ks @@ -0,0 +1,40 @@ +@LAZYGLOBAL off. + +run once "lib/node". + + +function target_ship { + // + // Return the target vessel even though a docking port might have been selected as the target. + // + if TARGET:istype("Part") { // e.g. if selected docking port as target + return TARGET:ship. + } + return TARGET. +} + + +function relative_velocity { + // + // Return the relative orbital velocity between the ship and our target in the target's inertial frame of reference. + // + if not HASTARGET { + return V(0,0,0). // avoids 'has no target' errors upon docking + } + return SHIP:velocity:orbit - target_ship():velocity:orbit. +} + + +function kill_relative_velocity { + // + // Kill relative velocity to target if it is above tolerance. + // + parameter tolerance is 0.1. + + if relative_velocity():mag < tolerance { + print "Relative velocity within tolerance of " + tolerance + " m/s". + return. + } + + execute_burn(-relative_velocity()). +}