Copy Orientation on Specified Axis? (2.49)

With Python 2.6.2 for blender version 2.49. I want [“OBCube”] to copy the orientation of [“OBSphere”] on only 1 axis and still keep the same data for the second and third. So, basically I want the cube to still stay upright when it is copying the orientation of the sphere. I attempted to do this with setting axis[0] and axis[1] to the same as the sphere and assigning axis[2] to the cube’s own axis[2] but it doesn’t seem to work. No errors in the console but I still think its a syntax error on my part. Here is my script (2.49)

scene = GameLogic.getCurrentScene()
cube = scene.objects[‘OBCube’]
sphere = scene.objects[‘OBSphere’]
cubeori = cube.orientation
sphereori = sphere.orientation
cubeori[0] = sphereori[0]
cubeori[1] = sphereori[1]
cubeori[2] = cubeori[2] # keeps same orientation on Z axis
cube.setOrientation(cubeori) # sets orientation to newest data.

I know that setOrientation() is deprecated but “cube.orientation = x” doesnt seem to work. But when I use setOrientation, it DOES change the orientation, but it always sets the cube’s orientation exactly to the sphere as if I never defined the new orientation of the cube.
Any ideas?

This might be what you’re looking for.

vec = sphere.worldOrientation.col[2].copy()
vec.z = 0
cube.alignAxisToVect(vec, 2)

Using this code, when I run the script, the python console says # AttributeError: ‘list’ object has no attribute ‘col’#

what is ‘col’ and how do I define it?

col[2] gets the third column of the orientation matrix which corresponds to the z-axis vector. I was using the new API, not the one for 2.49. Try using “orientation” instead of “worldOrientation”.

I believe col is an attribute also added in 2.6. You might want to try


sphere.orientation[2].copy()

I’m not sure, though, since I haven’t used 2.49 in quite awhile.

i used to use blender 2.49 like you, but then i took an arrow to the knee