How to move a pose (bones) in BGE? Given that I know how to do it outside the BGE

I want to change the pose (eye movement) of a model in response to some simple keyboard input.

The blender UI showed me that I can change the pose with this python code:

bpy.data.objects[“Rig”].pose.bones[“Bone”].location[0] += 0.1

If I run that from the game engine nothing happens in the game engine, but the model does change.

My question is how to achieve that same movement in the game engine?

I see some reference to setting up a keyframe and a channel, but that seemed like it needed to have a particular state defined. This pose can take on any real value in the range (-2.0, +2.0). Ultimately I’ll be feeding that value into blender from an external source via python code. This will be used as a demo feed from external “stimulus”.

1 Like

It’s easy enough for a simple bone, which means it’s not parented to (or extruded from) another bone. It also doesn’t have IK. If this is your case:


from bge import logic

cont = logic.getCurrentController()

own = cont.owner
scene = own.scene

armature = scene.objects["YourArmatureHere"]
bone = armature.channels["YourBoneHere"]

up = cont.sensors["up"]

loc = bone.location

if up.positive:
    loc.y += 0.05 #this moves the bone up on the local Y axis
    bone.location = loc

If you do have IK or parenting, look into joint_rotation. You can watch this video if you want a tutorial:

Looks at this script as well:

main_arm.channels['NAME OF THE BONE YOU WANT TO ROTATE'].joint_rotation[ x, y ,z]

(In this thread: https://stackoverflow.com/questions/6961438/change-bones-position-in-a-armature-in-blender-game-engine-using-python)

Or maybe search in the API:
https://docs.blender.org/api/blender_python_api_2_66_4/bge.types.BL_ArmatureChannel.html#bge.types.BL_Arm atureChannel.joint_rotation
(You might need another method, they’re all in there)

I managed to make something like this not a while ago, if you want a can send you a .blend

1 Like

as a last resort, you could just make the eyes a separate object and use a track to actuator.

or you could rotate an empty object, then use a copy rotation constraint. but armature constraints need to have an animation running on them to work (run armature doesnt always work).

or you could go back to using separate objects, but run logic on an empty. then do:

ori = empty.localOrientation

left_eye.localOrientation = ori
right_eye.localOrientation = ori
1 Like