kOS-scripts/lib/rendezvous.ks

29 lines
660 B
Plaintext
Raw Normal View History

2019-02-10 15:33:50 +01:00
@LAZYGLOBAL off.
run once "lib/node".
2019-02-12 23:33:17 +01:00
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.
}
2019-02-10 15:33:50 +01:00
function kill_relative_velocity {
parameter tolerance is 0.1.
2019-02-12 23:33:17 +01:00
if relative_velocity():mag > tolerance {
execute_burn(-relative_velocity()).
2019-02-10 15:33:50 +01:00
}
}