# bone/armature movements during game play

I am trying to simply move a bone that has been parented to a mesh in Blender 2.69. I want to do this in real-time - while the BGE is running. I linked an Always logic block to the python code seen below. Can anyone point out to me why this code does not move the 'Bone'?

   import bpy
import bge
import GameLogic as GL
#"bge.types.BL_ArmatureChannel(PyObjectPlus)" in the documentation means that BL_ArmatureChannel is a subclass of PyObjectPlus.
import mathutils

# The owner is an armature, so 'alien' will be a BL_ArmatureObject instead of KX_GameObject
cont1 = bge.logic.getCurrentController() #makes: SCA_PythonController
cubeBone=cont1.owner #makes: BL_ArmatureObject
#get the scene for the mouse and other things
scene=bge.logic.getCurrentScene()
#get a keyboard
keyboard = bge.logic.keyboard

def main1():

if bge.logic.KX_INPUT_ACTIVE == keyboard.events[bge.events.DOWNARROWKEY]:
#cubeBone.channels['Bone'].location = mathutils.Vector([3, 5, 8])
print (cubeBone.channels) #prints the channes available
print(cubeBone.channels['Bone'].rotation_euler)
print(cubeBone.channels['Bone'].joint_rotation)
#class: bge.types.KX_GameObject(SCA_IObject)
#cubeBone.channels('Bone').localPosition.z +=0.1
#cubeBone.channels('Bone').rotation_mode'XYZ'
#cubeBone.channels('Bone').rotation_euler([5,5,5])
#cubeBone.channels('Bone').joint_rotation([0.0,0.0,0.1], True)
cubeBone.channels['Bone'].rotation_mode = GL.ROT_MODE_XYZ
cubeBone.channels['Bone'].rotation_euler=[25,25,25] #BL_ArmatureChannel.rotation_euler
print("bone moved")
cubeBone.update()
print(cubeBone.channels['Bone'].rotation_euler)
############# end of main ###############################

main1()
cubeBone.update()


The Console prints out the new vectors that are changed, but the animation does not move. I found this post: Controlling armature through python but there are mixed answers and they are not very helpful for noobs. Thanks guys

• I see my problem is based on my thinking that the line: "mainArm=obj.get('Mouth')" would get the armature and pass it to the variable mainArm. So is there a better way of accessing the armature and its bones? – CubeBot88 Feb 17 '14 at 15:47
• I have found one person on the internet who seems to have working code for moving bones through python code in real-time. Can anyone figure out how to add bones to move, the code is simple yet I cannot get a 'b3' to move... Check it out bonTest.blend file in: [link]blenderartists.org/forum/… – CubeBot88 Feb 19 '14 at 11:48

I am not sure if you have tried this,

Connect a always sensor to a and controller to a Run armature brick,

if this is not your issue, just add a empty for each bone you want to manipulate,

have the bone use copy rotation on the empty,

Rotate the empty.

Now you can move bones in the bge (I do it all the time for heads tracking cursors etc)

• What do you mean by "have the bone use copy rotation on the empty"? Maybe you can help here? – yPhil Mar 24 '15 at 12:07
• if you use copy rotation on the bone, to a empty, then you can rotate the empty to rotate the bone. copy rotation is a constraint. – BluePrintRandom Mar 24 '15 at 16:46