skinned ragdoll test. -Super Worm-

simple 2 bone skinned rag doll using python, action ipos, and “property” action actuators.

it was a cube with one loop cut in the middle, but after i started moving it around, i thought “it needs a head so i can tell which end is the front”
after that, i thought, “this kinda looks like a worm…” so now it is pink.

hope to get some people laughing out loud. (but seriously, don’t spam “lol. nice”)

i’m sharing the .blend so it is unix friendly. any curious people are welcome to rip the blend apart. if you want to use any pieces of it for your own project, that is fine, as long as i get some credit. if someone wants to actually make a real game out of this, that would probably be pretty funny.

and now, the blend you’ve all been waiting for, (right?):
Super Worm!!!
<3bone version>

really nice !

I Don’t know how you do this but I might check it out to see if it’s possible to rig a simple character with your method

lol. it’d have to be pretty simple. this method calculates 2 angles and a distance for each bone. it also requires an extra bone for each bone. and if you don’t turn on “hinge” for the right bones, it blows up. you also need a action for each bone.
the good thing is, anything that is not rag doll can be animated. so you could passably make just the arms of a character rag doll. good luck if you try. and if you get anything to work, post it :slight_smile:

Great! With this tool i can finally imagine cloth simulation in Real-Time!

Keep up the good work!

is not possible to animate more than 2 bones ?

you can animate more than to. let me explain how to add a bone to my worm as simply as i can:

note: yes x and y get mixed up. just fallow the directions. or skip it and download the blend

1st:
extrude the last bone (Bone.001) up a bit (0.400).

2nd:
extrude that same bone (Bone.001) up again. (1.00)

3rd:
select the new bone, and turn off “con” (in “editing” (f9))

4th:
in the menu right next to the “con” button, select the first bone you made.

that is it for the armature

5th:
duplicate the last object in your actual chain (Cube.003) and move it so that it’s center is at the beginning of the 2 bones you made.

6th:
edit the new object so that it dose not intersect the one you duplicated

7th:
with the new object selected, under object (f7), change the “toObject” value in the rigid body constraint to the name of the previous link in the chain (Cube.003)

done with the dynamics.

8th:
select the armature again. go to logic (f4) and add a new property. call the property “object4”, make it a string, and set the value to “Cube”. than edit the value of the property called “object3” and change it to the name of the new physics object you made. (Cube.004)

9th:
add 2 more properties. called bcx and bcy. (or whatever you want if you can remember it.) keep them as floats.

10th:
in the text window, (shift-f11) add this to the “angles” script:

from GameLogic import *
from math import *
con = getCurrentController()
o = con.getOwner()

def dist(pos,posi):
   Z = (posi[2])-(pos[2])
   Y = (posi[1])-(pos[1])
   X = (posi[0])-(pos[0])
   return sqrt((X)*(X) + (Y)*(Y) + (Z)*(Z))

def object(name):
    return GameLogic.getCurrentScene().getObjectList()["OB"+name]

o.setPosition(object(o.object1).getPosition())

obj1 = object(o.object1).getPosition()
obj2 = object(o.object2).getPosition()
obj3 = object(o.object3).getPosition()
obj4 = object(o.object4).getPosition() ##&lt;---this is new

dx = obj2[0] - obj1[0]
dy = obj2[1] - obj1[1]
dz = obj2[2] - obj1[2]
o.bax = -degrees(atan2(dx,dy))
o.bay = -degrees(atan2(sqrt(dy*dy + dx*dx),dz))

dx = obj3[0] - obj2[0]
dy = obj3[1] - obj2[1]
dz = obj3[2] - obj2[2]
o.bbx = -degrees(atan2(dx,dy))
o.bby = -degrees(atan2(sqrt(dy*dy + dx*dx),dz))

##
##this is new##
##
dx = obj4[0] - obj3[0]
dy = obj4[1] - obj3[1]
dz = obj4[2] - obj3[2]
o.bcx = -degrees(atan2(dx,dy))
o.bcy = -degrees(atan2(sqrt(dy*dy + dx*dx),dz))

11th:
go into pose mode with the armature, and select the smaller new bone you made. in the action window, make a new action. IMPORTANT: make sure there are no channels besides the ONE bone we are working with. call it “bone3X”

12th:
insert a keyframe for rot at the fallowing frames-values.
frame 1 RotY = -180
frame 91 RotY = -90
frame 181 = RotY = 0
frame 271 = RotY = 90
frame 361 = RotY = 180

13th:
select all the curves in the IPO window (shift f6) and move them back -181 on the x axis.

14th:
repeat 11-13 for the second new bone on the X axis. call the action bone3Y

15th:
add 2 actuators to the armature. connect them to the “and” controller. make them both actions. change “play” to “property” set ones action to bone3X and the property to bcx. set the other to bone3Y and the property bcy.

16th:
just add something to the worm mesh to be skinned onto the new bone. i think thats it…

dizzy yet?

<.blend>

Very nice, I like this skinned ragdoll, too bad it requires all this code.

BTW: Have you tried using these functions for skinned ragdolls?
http://www.tutorialsforblender3d.com/GameModule/ClassKX_VertexProxy.html
I tried using such a function to test snap a vert from one object to another and was able to move a vert but couldn’t snap it to another object. This code could move a verticie, but not to the right spot and it crashed when I changed the x value to ‘pos’


c=GameLogic.getCurrentController()
ob=c.getOwner()
objList = GameLogic.getCurrentScene().getObjectList()
cube = objList["OBCube"]
pos = cube.getPosition()
target = objList["OBT"]
mesh = target.getMesh()
vert  = mesh.getVertex( 0, 0)
vert.setXYZ([ 1, 1.0, -0.5])

I gonna try this the next week but the question I have is since you animating the bones with the property actuator is not possible to set with a function ? I mean a sort of swith which enable the ragdoll thing on. Like if dead property == 1 …
I don’t know … I don’t have the time to look at your code but I don’t see why it wont be impossible to make it since the harder thing is done.

try this:


c=GameLogic.getCurrentController()
ob=c.getOwner()
objList = GameLogic.getCurrentScene().getObjectList()
cube = objList["OBCube"]
pos = cube.getPosition()
target = objList["OBT"]
tpos = target.getPosition()
mesh = target.getMesh()
vert  = mesh.getVertex( 0, 0)
vert.setXYZ([pos[0]-tpos[0], pos[1]-tpos[1], pos[2]-tpos[2]])

untested

It works, thanks.

I almost got it right due in part to that python function reference site, I’m just not an expert at python yet.

Theoretically, if I attatched all the verticies to objects parented to the jointed rigid body objects it should give the appearence of a skinned ragdoll.

that would theoretically work, but it would take even more code than my example, and the skinning would have to be hard coded into python. This was just meant to be an example of how it is possible to do skinned rag dolls right now in blender. if anyone seriously wants rag dolls in a game they are making, it would be best to wait until a nice coder puts it in.

I could tell your way is shorter, I found out I need 100’s of lines of code to skin two rigid bodies.

I agree about the best way is to wait for someone to hardcode a system in, perhaps a way like this.

1). Create a mesh
2). Parent an armature to the mesh and skin it
3). Parent a rigid body object to each bone with rigid body joint constraints
4). Use the rigid bodies to move the bones.

Excuse me for posting again but I found this at that reference site

getVertexArrayLength(matID)
Returns the number of vertexes in a material.

Return type: integer

matID:
Type: integer

An object can have more than one material on it. 0 is the first material. 1 is the second. Etc.

Sample Code 1:

get controller

controller = GameLogic.getCurrentController()

get the object that owns this controller

owner = controller.getOwner()

get the mesh

mesh = owner.getMesh()

get the number of vertexes in the first material

vertex = mesh.getVertexArrayLength(0)

Sample Code 2:

get current scene

scene = GameLogic.getCurrentScene()

get list of objects

objList = scene.getObjectList()

get object named Target

target = objList[“OBTarget”}

get the mesh

mesh = target.getMesh()

get the number of vertexes in the first material

vertex = mesh.getVertexArrayLength(0)

Is there any way to skin rigid bodies using less code with this function? It says it returns all the verticies in a material and not just one.

to skin a rigid body using a method where you move the verts in a mesh using a script, you would basically have to re-write the armature code.

I finally got th etime to dive into your code but I have some question about the way you use the property action actuator. How did you get the angles in you code and I don’t understand how you use the list to get the boxes objects.

Last question is it possible to set up a switch on/off on this small ragdoll worm ? And if it’s possible to animate the object when it’s switch off ?

I finally got the time to look at your script and try to do the same but that my problem, blender is crashing and I don’t know why So there is the blend if someone know why it would be very usefull.

I figure it out what was the problem ! You cannot use same code for two different objects. I’ve made a sort of switch on/off to enable the ragdoll and playing an animation with the same bone and maybe make an mix up physics and keyframing animation. I’ve a long way too go since I made a complete ragdoll but It’s can be a thing if bring this concept to what I’m thinking.

stay tune I’ll post smoethin next week.

Cool. a bit of a problem you may run into with a full rag-doll is that when bones are pointing down, they spin. it is because of how i am doing the angles. If it bothers you, and you are good with math and python, you could make it so that the second bone can go past straight down for, say, 10 degrees. it would take some scripting, but it would get rid of the spinning. (oh, and the same thing for straight up)

I’m looking forward to what you come up with.

I don’t really understand the problem but maybe if you explain me how your code ( maths function ) is working ( I’m not good enough at math that my problem ) I’ll try to figure out how to avoid this spinning problem and how I could maybe improve it for my needs.

Umm…Sendspace is being dumb. It says it is at full capacity or something. can someone who can download it upload it on savefile.com or somewhere else please? I’ve been trying to make skinned ragdolls forever.