41 lines
975 B
Plaintext
41 lines
975 B
Plaintext
@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()).
|
|
}
|