Realtime armature control in game engine

Hi - I’m very new to Blender. I am trying to do real time control of a robot arm (actually it is the shuttle Canadarm). So, while the user presses a button I would like one particular bone to move.

The arm has 3 sections to which I have added 3 bones. In pose mode, I can control each bone individually. But I can’t do this in the Game Engine. I can only control the entire armature (all 3 bones).

How do I control each bone individually?

Thanks

Can someone please confirm if this MUST be done in Python (and perhaps point to s starting example?) or if there is another way to do this?

I tried experimenting with adding a ‘control’ bone (bone not attached to the Canadarm armature) and then tried to constrain one of the Canadarm armature bones to the control bone. So when I move the control bone the associated Canadarm bone moves accordingly. Works fine in 3D model view but not in real time game engine! Is there some way to make this work real time or should I go down the Python route?

can make different action and start it with 3 actuators action differents.

key A->AND->ActionA
key B->AND->ActionB
key C->AND->ActionC

select “play mode” in the actuators.
i think which this work, and is easy .

with python is very difficult move the bone

MarcoIT - but wouldn’t Actions be limited to a predefined animation? What I’m looking for is, for example, while user presses keyA the arm rotates clockwise in X direction and stops only when user releases keyA. If I use actions, isn’t the amount of movement pre-defined? Sorry, I don’t know actions capabilities - I am new to Blender!

yes, I think it is as you say,

to rotate the bone on the X axis (rotation no “predefinied”), you have to use python,
i Think

something I can do, but I felt there were some bugs (at least in older versions)

I try to do some tests …

ok, this is the best I can for now, I never managed to turn the bones with python :slight_smile:

the order XYZ, it seems wrong ,now, but it works.

Notes: bone-> Transform-> rotation mode
is not default (default is quaternion)

Attachments

bonTest.blend (60.8 KB)

I had to do something similar a while back.

This in a nut shell is how it worked:

1/My rig was for a human
2/I had 6 separate armatures for the rig.
3/ Five were for separate animation (head armature, spine-arms armature, hips armature, legs armature, and master armature). This way each section could have it’s own logic and do things in a unique way). Each one of these needed to me constrained to it’s logical parent (ie: Head to spine)
4/ the 6th rig was a for geometry deformations. Each bone though has to be constrained (transformation and rotation) to it sister animation bone. The geometry was parented and weighted to this deformer armature.

This set up has been working for me so far. My character has idle, walk, and run cycles, but at the same time… it randomly looks to see who’s behind it while still doing it’s cycle. I couldn’t do this and have it look as good by just blending between cycles.
When I finish my game (hopefully for the summer game contest) I’ll share my files.

This might seem complicated, but for those of us who aren’t programmer savvy, is one way to go.
M

P.S. If I get a chance today, I’ll try and set something up (like the Canada arm) for you with this methodology.

MarcoIT - thanks! I’ll take a look this evening.

Molino - I have been thinking about something similar to what you describe using empties. So, for each arm segment I have separate armature but use empties:

Empty1 -> Armature1 -> Empty2 -> Armature2…

Parent Armature1 to Empty1 and then parent Empty2 to Empty1?

Alternatively, perhaps parent individual bones to empties then control empties? So, in the latter method you have 3 bones already interconnected (making up the arm - i.e. one single armature made of 3 bones) but the empty is used for control (so I set some logic on the empty). So, you end up with bone as parent of an arm segment; and then empty as parent of bone - i.e. Empty -> Bone -> Arm Segment.

What do you think? I’ll give it a go this evening I think…

Just a quick update. I have done a quick test that just has 3 separate armatures, each with a single bone. I parent the bone to an arm segment. Then I parent one armature to another. Seems to work. Need to do some more work…

Thanks for the hints.

Not sure if my posts are getting through. Sometimes it says something about wait for moderator. Anyway, I made 3 separate armatures with a single bone in each. Parented these armatures to the individual arm segments. Then parented each armature bone to the previous bone in the chain. Seems to work so thanks for the hints and tips.

Anyone know how to constrain/limit bone rotation in the game engine (i.e. real time)?

Great work Marko. I was looking for this too. Thanks a lot !

muy bien el trabajo hecho

How would you go for scaling the bone (hence the object)?

I took your example and I make them scale with the following script:

import bge
from bge import logic

def bone(cn):
ow=cn.owner
key = bge.logic.keyboard.events

b1=ow.channels["b1"]
b2=ow.channels["b2"]



rot=b2.rotation_euler
s=b1.scale
add=0.01


if key[bge.events.UPARROWKEY]:
    b1.scale=(s[0] + add, s[1] + add, s[2] + add)
if key[bge.events.DOWNARROWKEY]:
    b1.scale=(s[0] - add, s[1] - add, s[2] - add)
    
if key[bge.events.WKEY]:
    b2.rotation_euler=(rot[0] + add, rot[1], rot[2])

if key[bge.events.SKEY]:
    b2.rotation_euler=(rot[0] - add, rot[1], rot[2])
            
if key[bge.events.AKEY]:
    b2.rotation_euler=(rot[0], rot[1] + add, rot[2]      )

if key[bge.events.DKEY]:
    b2.rotation_euler=(rot[0], rot[1] - add, rot[2]      )
    
    
    
    

"""
rot=b2.rotation_euler

b2.rotation_euler=(rot[0]+0.01 ,0, 0)



print(a)
"""

b2 scales the same as b1 because b2 is child of b1

how would you do it if you want to use a joystick instead on the key board?

Hi guys, I have spent ages trying to modify the bonTest.blend file posted by MarcoIT but I cannot replicate the armature movements in another .blend file. I also cannot add extra bones to move in the original file. Is there some setting or special parenting that needs to be done in order to get the bones to move the mesh? My printouts show that the bones’ angles are changing, but nothing happens in my game screen… This problem is driving me mad is seems so simple… Any help with my file attached would be greatly appreciated.
FaceBonePythonTest.blend (647 KB)

Always run armature?

I suggest to go with the solution mentioned in post #3.

Predefined Actions
There is nothing wrong with predefined actions. They exactly describe how an animation should be performed. They can include limits, non-linear animation and any “hick-up” you want. You can even see the graphs in an graphical editor. You can create endless actions (see extend mode in graph editor). Predefined actions are much easier to design then trying to develop formulas to create the necessary transformations via code.

An action is like a function: y = fct(x)
you control the current output with the keyframe: pose = action( keyframe )

Another benefit of this view is, you can include as many transformations as you like. You are not restricted to a single bone/channel. E.g. you can manipulate a complete walkcycle with just one action (try that with Python :wink: ).

User controlled playback
Now you might argument: It always plays the same.

It plays the same only, if you use the (most commonly use-case) play mode. You can determine what keyframe to be played by using the property mode at the ActionActuator. (Do not forget to activate the actuator after modifying the property).
This way you can change the property with any method you like (PropertyActuators, Python). This is a pretty simple but very powerful method.

Combine Actions
You still think you need a more dynamic animation?

Indeed a single action is pretty “one dimensional” as you have one input (the keyframe) only. But you can combine actions to add another input. This way you get a two (and more-) dimensional action:

pose = fct( actionA(keyframeA, actionB(keyframeB) )

There are several methods to achieve this effect:
A) have a separate Armature for each action (pretty heavy and hard to manage)
B) have separate bones for each action (actions should not share any channels/bones)
C) use action layers to blend actions together.

If you look at a real robot you will find the same method: Each actuator is an engine that follows exactly one path (turning or translating) within some limits. The complex motion is a result of combining the “atomic” animations.

Do you have any video example or blend file? Could it do how if 2 character have 2 different walk animation? I don’t understand

Hi! Sorry for reopen this thread. I’m new in blender and I need to control the bones in the way you explained here but I need something additional. I have a simple armature with several bones, one behind the other. Then I need to move that armature over a irregular surface and depending if the surface has a curve the armature has to deform. And the flexion of the armature cannot be predefined. It is possible to do this in Blender? Thanks!