Thanks for your reply Goran!
I’ve spent a few hours putting this together and debugging error messages (took me a while to figure out what each one meant, but I did it ).
But I still did something wrong though, because it’s not copying the rotation. (and there is no error message telling me why)
Here is the .blend, I think maybe I did something wrong on the logic side?
The file you posted does raise an error at line 19 since you left target as a list instead of a game object. You need to set target to an individual object from the list before you use target.worldOrientation.
Thanks blenderer2012, my file was behaving odd as a result of the Euler rotation, I changed it to quaternion and it behaved better.
Euler has this odd hate for 360 degree rotations, it can’t seem to interpret how the object should reach a particular point in rotation.
I needed to copy only one axis because I need the other axis (axises? axies?) to be influenced by other things.
So what I have now is this:
import bge
scene = bge.logic.getCurrentScene()
cont = bge.logic.getCurrentController()
own = cont.owner
# objects with property
objects_with_prop = [o for o in scene.objects if "CopyMe" in o]
target = objects_with_prop
# closet
dist = lambda o: (o.worldPosition - own.worldPosition).magnitude
object_distance = [(o, dist(o)) for o in objects_with_prop]
object_distance.sort(key=lambda t: t[1])
closest = object_distance[0][0]
target = closest
# copy rotation
eu_own = own.worldOrientation.to_quaternion()
eu_target = target.worldOrientation.to_quaternion()
eu_own.z = eu_target.z
eu_own.w = eu_target.w
own.worldOrientation = eu_own
Euler has been such a headache because it doesn’t do 360 degrees (some years ago, I screamed at my monitor in rage as I attempted to make my character spin)
Knowing this now, I don’t use Euler because it produces odd results like you saw in my blend, you guys gave me the code and I simply fit it to my needs (I didn’t think to post my corrected blend lol)