Ragdoll control problem

Hi there,

I’m trying to control a 2-link ragdoll, the idea is to simulate the arm of a robot. If you’ve seen my other posts, I’ve been trying to move an armature in the GameEngine… I was still learning the basics in Blender; now I know it is not possible to control armatures in real time, so the only option is to control boxes, hope to be right about this, any comments are welcome.
I’m using a RigidBody Joint constraint (I want to check a 2D rotation to simplify the problem, hinge -> elbow) from the lower arm to the upper arm; and another one (hinge -> shoulder) from the upper arm to the “body”. I’m using the Up and Down arrows to move the lower arm and the Left and Right arrow to move the upper arm. All blocks are “dynamic” except for the body which is “static”. I can change the position/speed of the “shoulder” and the “elbow”, no problems there.
My problem:
I thought that parenting the lower arm to the upper arm would be enough for blocking the rotation of the lower arm when moving the upper arm alone. When not parented both links rotate as they should but the lower arm does NOT follow the rotation of the upper arm. When parented the lower arm MOVES the upper arm which is NOT what I want; and when moving the upper arm then the lower arm follows, this part at least is what I wanted.
I’m attaching the .blend and the .py file is at the bottom of this messege. I hope you guys have some time to check this and thanks for your help.
Apollo

firstArm.py

import GameLogic as g

cont  = g.getCurrentController()
own = cont.owner		
move = cont.actuators[0]

if own.name == "OBLArm":
	press1 = cont.sensors["up"]
	press0 = cont.sensors["dwn"]
elif own.name == "OBUArm":
	press1 = cont.sensors["right"]
	press0 = cont.sensors["left"]

if press1.positive:
       own['go'] = 1
elif press0.positive:
       own['go'] = 0

cont.deactivate(move)
speed = move.dRot[2]
if own['go'] == 1:
	speed = speed + 0.005
else:
	speed = speed - 0.005
move.dRot = [0.0, 0.0, speed]
cont.activate(move)

Attachments

firstArm.blend (151 KB)

It is possible to control armatures in real time :smiley:

This little (read not) documented feature has been added fairly recently (2.49a release) by ideasman42.

Unfortunately, I can’t find the thread that info about this feature was posted in. :o

BoneTracking_python.blend (41.7 KB)

This file is the one that I downloaded from that thread. The .blend was created by ideasman42 as an example for implementation of this feature.

This file uses a dummy action to provide access to bones that have keys in that action. In this case, bones correspond to the action channels on the action actuator. Channel (bone) location/scale/rotation can be set using Python in realtime, thus controlling the armature.

The file is fairly self explanatory, but to improve my understanding of this documentation-less feature, I made extensive use of the dir() function.

If the actuator set to your dummy action is called DummyAction then running the following script segment will print out the bone information and provides the option to set alternative values for the bone position, scale and rotation in real time.


cont = GameLogic.getCurrentController()

act = cont.actuators["DummyAction"]

channelList = act.channelNames

for channel in channelList:
     print act.getChannel(channel)

     #To get and set bone values:

     loc, scale, rot = act.getChannel(channel)
     #Change values for loc, scale, rot here
     act.setChannel(channel, loc, scale, rot)

I say again… This feature was added in Blender 2.49a so you will need the current official release or later to use this feature. Blender 2.49 does not support this functionality.

Hope this little gem of a feature helps you out. Have fun. :slight_smile:

Edit:

I’ve been looking into this in order to use a ragdoll to set the position of an armature, thus enabling rag doll deformation of a mesh in the game engine. The project is kinda on hold for a while for me to learn about quaternion algebra. This is required in order to translate the global rotations of rigid body objects into a hierarchy of rotations to be applied to each bone in the armature in turn. I’m making pretty good progress with the quaternions and am probably ready to resume the project soon. It’s far from ready for public release and the code is pretty messy, but if you are interested and you think you could help me or I could help you then pm me and I’ll upload the files and send you the links.

Hi FunkyWyrm,
thanks for the tip about ideasman42 file; I’ve downloaded and studied… it seems to be exactly what I need but I get some strange effect when trying to replicate it from zero. My “worm” starts with an offset from the blocks when running the game engine and I have no clue where to find this bug.
As I told you, my goal is to rotate two or more links… like arms or legs, and control the rotation of each joint with a number (I’ve been testing with the Up & Down keys in the keyboard). So, using the same approach from ideasman42 I’ve been trying to rotate each block instead of moving the whole structure. I’m still getting this offset of the mesh so there is something I must be missing, but the biggest question is how to copy the block’s worlOrientation into the Quaternion required by the bone channel. Do you know how to do this?
Thanks for any help,
Apollo

PS: I forgot to mention that I also tried to constrain the blocks with RigidBody joints as before and I get the motion of the mesh in a much simpler way… the problem is that I still can’t figure out how to lock the motion of a child block when rotating a parent. The child stays with the same world orientation instead of staying with the local orientation.

I’m going away for the weekend so have to put this off again :frowning:

But…

To create a quaternion from an object’s world orientation:

import Mathutils as M

ob = GameLogic.getCurrentController().owner

orientationQuat = M.Matrix(*ob.orientation).toQuat()

print orientationQuat

Simple enough, but this is where my problems start. This is the global orientation, but the bone rotation quaternion is the rotation from rest in bone space.

Bone space is the rest orientation of the bone in world space that has been successively rotated by each bone further up the parenting hierarchy.

Managing this hierarchy of rotations and orientations is the source of my confusion.

As I said, I can’t work on this right now, but I spotted an alternative version of the setChannel() function in the game engine API here. Maybe this would enable direct use of the world matrix of the object that is guiding the armature. I really want to test this out as it could be much simpler. I’m worried about gimball lock though…

Good luck.

FunkyWyrm:could you post a .blend with wat u have come up with. please.

Hi again FunkyWyrm,
Hi Hellooo too,

thanks again for the new tip, I’d have never got the * part before the orientation matrix. I am using the applyRotation function to rotate the different blocks, then I copy the orientation of these blocks into the quaternions of the bones using the tip you sent. The mesh deforms according to my input (Up/Down keys to increase/decrease the rate of change of the rotation angles. NumPads 1/2/3/4 to activate the joint I want to move).
There are a couple of problems that I still need to solve (with your help if possible and if you have time to check the blend file):

  1. Child blocks follow their parents but not well… the more a parent is rotated, the larger the offset of the child is. Using rigdoll blocks that is not a problem, the blocks stay attached always at the same point… the problem with them is that they don’t rotate with their parents.
  2. The mesh does NOT follow the blocks… or I guess, the armature doesn’t follow the exact position of the blocks. I have no idea why…
    Finally, I wanted to say that I also had a lot of problems managing the hierarchy of bone rotations and orientations. What I did was to put the axis of all bones in the same configuration as the axis of the whole armature. Bones seem to have the Y axis pointing outwards and it was impossible (for me) to change that to Z or X.
    I’m attaching the .blend file so you can check it… and for you too Hellooo so I hope you can give me some feedback and suggestions on how to make this work as it should.
    Apollo

Attachments

armatV01.blend (198 KB)

Apollo,

wat u need to make that work is a 2.9 release, if u have said version try another build from graphicall.com and visa versa.

hope that helps

Hellooo

Hi Hellooo,
could you explain that a little bit more? 2.9 release of ??? don’t understand what graphicall.com and viceversa meant either.

apollo

hi again,

just a quick note to say that after a long fight I manage to get what I wanted. I’m not using ragdolls in the end due to my impossibility of rotating child blocks together with their parents. The solution was to directly control the rotation of normal blocks… then follow the same approach as ideasman42 file, which is copy the info from the blocks to the armature. Thanks for the help,

apollo