The following code will give you the range, heading and pitch to the object:
def GetTarget(self, tgt, base):
"""Calculate the relative range, abs heading and abs pitch from base to target."""
# Get the relative coordinates of the NodePath.
t = tgt.model.getPos(base);
x = t.getX();
y = t.getY();
z = t.getZ();
# Heading to target.
a = math.degrees( math.atan2(y, x) ) + 90;
if (a < 0):
a += 360;
# Range to target.
r = math.sqrt( (x * x ) + (y * y) );
r = math.sqrt( (r * r ) + (z * z) );
# Azimuth to target.
b = math.degrees( math.atan2(r, z) ) - 90;
if (b < 0):
b += 360;
return r, a, b;