Search code examples
pythonmayadirection

How to get direction from 2 positions in Maya?


Could somebody help me? I am trying to get the direction value in worldSpace based on 2 given positions in Maya. How can I do that in python? Is it not just subtracting the 2 positions?

thanks a lot!


Solution

  • Indeed, it's the difference of the two position vectors, with pymel it can look like this:

    import pymel.core as pm    
    v = pm.PyNode("locator2").translate.get() - pm.PyNode("locator1").translate.get()
    

    Open Maya version:

    import maya.api.OpenMaya as om
    v = om.MVector([1,2,3]) - om.MVector([4,5,6])