Solved the issue!
Turns out the orientation needs to be reset before making the rotation. If the object was already pointing one way, trying to run the function again is what results in the spasm.
def aim(object, target, reference_obj, axis, factor):
object.worldOrientation = reference_obj.worldOrientation
diff = object.worldOrientation.col[axis].rotation_difference(object.getVectTo(target) * factor)
object.worldOrientation = object.worldOrientation @ diff.to_matrix()
reference_obj is the orientation to match before aligning
axis is the axis to align
factor can be set to -1 to invert the axis
look-toward-object-issue-FIX.blend (763.0 KB)
Currently working on setting/locking the rotation of whichever axis is being aligned (for example, if Z is being aligned, it doesn’t have to rotate; only X and Y need to be adjusted).