Implement TargetVessel.Distance
Vergutto opened this issue ยท 2 comments
Would make rendezvous a lot easier, and wouldn't have to play with the coordinate system, which is challenging on inclined orbits and when target goes from positive to negative coordinates. It's visible in game so most likely not that difficult to implement? (C#)
There is no obvious way to add this to the API in a clean manner. As there is no "TargetVessel" object in kRPC. SpaceCenter.TargetVessel just returns a plain Vessel object.
I also don't think it's hard to implement this in a client program. You just need to get the position of the target vessel, in the active vessels reference frame, and compute the magnitude of that vector. For example in python:
import krpc
conn = krpc.connect()
vessel = conn.space_center.active_vessel
target = conn.space_center.vessels[1] # the target vessel
print(target.name)
while True:
v = target.flight(vessel.reference_frame).center_of_mass
import math
print(math.sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]))
Also, doing it yourself means you can choose exactly what you are measuring the distance to. Do you want distance to the center of mass? A docking port? Or some other part of the target vessel?
I'm open to argument if you have a good reason this should be added though.