distance function?

does it exist?

(node1.getPos(render) - node2.getPos(render)).length()


And I get to learn something new myself. :slight_smile:

yes, it does exist.


iirc it returns the distance given the coordinate-space of node1.

So do I.

Thomas wins :slight_smile:

What if node1 (or one of node1’s parent nodes) has scale set?
Be careful with things which are bound to a local coordinate space: distance is not distance!

>>> from panda3d.core import Point3
>>> from panda3d.core import NodePath
>>> render = NodePath('render')
>>> np1 = render.attachNewNode('1')
>>> np2 = np1.attachNewNode('2')
>>> np1.setScale(2)
>>> np2.setPos(Point3(3,0,0))
>>> render.ls()
PandaNode render
  PandaNode 1 T:(scale 2)
    PandaNode 2 T:(pos 3 0 0)
>>> np1.getDistance(np2)
>>> (np1.getPos(render) - np2.getPos(render)).length()
>>> np1.getPos(np2).length()

Sidenote for the curious: In physics - cosmology to be more precise - we have several different definitions of distance, depending on how the distance is measured. Some of them even have strange behaviour: objects which get closer might get smaller (and not bigger)!

Looking through my code I actually use .lengthSquared() most of the time because it is faster and I am just using it to test if something is within range of something else. So if you want to know if the length is more or less than 5, you could compare the result of lengthSquared to 5*5.