kOS-scripts/lib/rendezvous.ks
Casper V. Kristensen 49b5236521
Implement docking.
2019-02-12 23:33:17 +01:00

29 lines
660 B
Plaintext

@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()).
}
}