Pyhton script Copy Z rotation from child to parent.

Hey guys I hope you can help me with this or I may have to scrap this project AGAIN.

Here is the fileProject gemini.blend (531 KB)
The script is set to use module activation mode the part that is driving me crazy is def sprint(cont):

I have a character with legs that walk and strafe and a torso that swivels left to right up and down (courtesy of Jacob Merrill’s Video)
The movement is no concern. What is the concern is that I want the legs to snap to the rotation of the torso when you press right mouse and the torso to snap to the rotation of the legs when you press left shift. So far it is a disaster I tried

own.worldOrientation = own.children['playerBox_torso'].worldOrientation

Obviously it copies all the rotations and that won’t work because it causes the legs to rotate on the Y axis and I can’t have that ,so, all I want is the Z rotation. I tried

own.worldOrientation.to_euler().z = own.children['playerBox_torso'].worldOrientation.to_euler().z

but it seams to do NOTHING.

There is also the problem that when the rotation is copied the torso doesn’t stay in the direction of the legs but the first problem is more pressing.

I hope you guys can help if you need more info please ask I’ll be refreshing this page constantly.


Project gemini.blend (531 KB)

own.worldOrientation = own.children['playerBox_torso'].worldOrientation

do use z or x or y then.

own.worldOrientation.col[0] = own.children['playerBox_torso'].worldOrientation.col[0]

own.worldOrientation.col[0] = x, 1=y 2 =z

it gave me an invalid syntax 2=y

I mean 2=z

I’m sorry I’m an amateur at python. I tried it works. Thanks!!

Okay it doesn’t work perfectly but it helped some


I will try and take a look at your setup before bed tonight.

This should be about what you need
(grabs a copy of the target rot, gradually moves to it over 10 frames, while the legs line back up centered with the torso)

if keypress and 'StoredRot' not in own:
    if own['StoredTimer']>=1:
      if 'StoredRot' in own:
           del own['StoredRot']
           del own['StoredTimer']