BGE: How to set the Constraint Axis to an object coordinate I need to constrain an object using the axis of another object (my problem is related to the axis direction: there is no "distance between objects" constraint; you have to use the local or global axis to check). So, I made this parented object that tracks the whole time to another one, and from it I want the Y axis.

Using this tutorial for reference, I did the following:

#CONSTRAINT
direction = cont.actuators['Direction'] #the constraint actuator
face = sce.objects['Facer'] #the facing object
faco = face.localOrientation[1] #here we are (this gives me a 3x3 matrix)
                                #but i only want to use the Y value
                                #I’ve tried out even 0, and 2 but wont work

def constra():
    direction.direction = faco #this isn't running as it should
    cont.activate(direction)


There are no errors in the terminal. It's just not doing what it should do. I think I'm wrong, and he didn't want the orientation of the object, but some other stuff maybe...
Does the object need to be parented? I will make an example that presumes it doesn't. If you explicitly need parented objects, this script will not work as it is.

If you transform the orientation matrix of the source object into an euler and then pass it on to the target object's world orientation as a matrix, you should get what you are looking for.

In a nutshell: get matrix -> change to euler -> modify euler -> change to matrix -> give to the object you want

Hook this up to a TRUE level pulse triggering sensor with a frequency of your choice.

import bge
import mathutils

sce = bge.logic.getCurrentScene()
face = sce.objects['Facer']
facY = face.worldOrientation.to_euler()[1] #Now we have the Y-axis rotation
facTar = sce.objects['Facingtarget']       #This is the target object we modify
newRotList = [facTar.worldOrientation.to_euler()[0],facY,facTar.worldOrientation.to_euler()[2]] #Now we have a list
newRot = mathutils.Euler(newRotList).to_matrix()   #Now we have the matrix we need
facTar.worldOrientation = newRot    #The orientation has been modified