Non PID Ragdoll based on Jackii's work made for "Wrectified"

oh, I see why you’re using the cubes at the joints, the cubes are parented to the bones and it’s easier to get the orientation and position of objects than bones, smart

the behaviour in the game is a bit imperfect, but there’s always room for improvement

yeah the biggest thing that made me,drop it was my own design choice

I used the ik target that was a external object for the aim in the arm to aim rather then playing a aim animation
and rotating the spine, which made melee almost impossible and it made things
like ladders much harder then they needed to be, probably going to add this back to wrectified after I get everything else working.

hey, so I got the rig setup, could you take a look and tell me what’s going on with it? https://www.mediafire.com/?84adp3danq7rku6
the action armature doesn’t have ik, and also, the whole rig is looking in the opposite direction of your rig on the z axis, so maybe we’ll need to tweak the math?

I took a look at it, and I don’t even notice a pattern to what is happening,

I will have to take a look at your math,

thanks, it’s the same as yours, I just wrote it in a way that’s easier for me to understand

i know it’s behaving erratically lol, believe me though the rag doll rig works, it’s just not animating correctly

I’m going to sleep soon, let me know if you figure anything out and I’ll get back with you later

make any discoveries jacob? If I could just get this working, I mean I’ve been planning in my head and on paper for quite some time and this idea is exactly what I came up with, I just couldn’t figure out how to ‘push’ a rigid body into a target position and orientation. That’s where you come in, the rig you have walking around right now, despite its limitations and imperfections, is something very valuable, at least to me and I want to take what you’ve done and apply it to my own rig, which you’ve seen. Maybe you could look at my code and rewrite it? Compared to your original code it looks correct to me but there must be something I’m missing

your dictionary code makes it confusing to me,

I use lists alot, but don’t mess with dictionaries so it will take me a moment to get the hang of it,

also, I did not check the orientations of your bone tags.

also, things are locked like moving stuff, and the 3d cursor is gone except in edit mode.
I never mess with that stuff so it is a little tricky to track stuff down,

in other-words, your clean coding style is at odds with my hackery, and your UI changes
confuse my simple lil mind :stuck_out_tongue:

if you use the original code style it will be much faster for me to debug

I’ll use your code as is, then see what my results are and that will also make it easier for you to debug. The UI? you can change it to whatever you like next to where you would look through your scenes at the top, I don’t have the UI that way for any particular reason it’s just how I happened to be working. Also, dictionaries, recommend you adopt using them, they make things so much easier. You’ll notice some of the variables have a G. in front of them, that just makes them global variables so I can access them from different scripts if I need to.

The dictionaries and all, that’s unimportant, it’s really all about preference, what’s important to me is the math you’re using.

And the reason things are locked is so I don’t accidentally move something out of place, you can unlock any object from the transform settings menu.

Here’s what I’ll do, use your original code, and unlock all objects, send you the file.
what do you mean by orientations of bone tags? I’m curious if it’s something important to how the rig works

import bge
from mathutils import Vector
import GameLogic as G

own = bge.logic.getCurrentController().owner
obj = bge.logic.getCurrentScene().objects

actionArma = obj[‘ActionArmature’]
bns = actionArma.channels

#HELP WITH GENERAL NAMES:
#when I say bound or boudning object or bounding game object, I’m referring to a rigid body object, that is
#part of the ragdoll, like the bounding object for thigh.r is the actual rigid body that will control the
#thigh.r bone
#when I say target, I mean the game object that is parented to each bone, we’ll use the ‘target’ objects
#transforms instead of trying to get the bone transforms which can be tricky and messy

#a list of strings, we’ll iterate through this and use the names to access each bone and it’s corresponding
#bounding box, as well as it’s corresponding strength
G.bonesList = ‘toe.L’, ‘toe.R’, ‘foot.L’, ‘foot.R’, ‘shin.L’, ‘shin.R’, ‘thigh.L’, ‘thigh.R’, ‘hips’, ‘spine’, ‘chest’,‘neck’, ‘head’, ‘upper_arm.L’, ‘upper_arm.R’, ‘forearm.L’, ‘forearm.R’, ‘hand.L’, ‘hand.R’

#these are the actual bones in the acton armature, if you call for example G.actionBones[‘foot.L’] it will return the
#actual foot.L bone
G.actionBones = {‘foot.L’: bns[‘foot.L’], ‘foot.R’: bns[‘foot.R’], ‘toe.L’: bns[‘toe.L’], ‘toe.R’: bns[‘toe.R’], ‘shin.L’: bns[‘shin.L’], ‘shin.R’: bns[‘shin.R’], ‘thigh.L’: bns[‘thigh.L’], ‘thigh.R’: bns[‘thigh.R’], ‘hips’: bns[‘hips’], ‘spine’: bns[‘spine’], ‘chest’: bns[‘chest’], ‘neck’: bns[‘neck’], ‘head’: bns[‘head’], ‘upper_arm.L’: bns[‘upper_arm.L’], ‘forearm.L’: bns[‘forearm.L’], ‘hand.L’: bns[‘hand.L’], ‘upper_arm.R’: bns[‘upper_arm.R’], ‘forearm.R’: bns[‘forearm.R’], ‘hand.R’: bns[‘hand.R’]}

#here we have the actual bounding rigid body objects, for example if you call G.bodyBounds[‘toe.L’] it will return the
#actual game object ‘bound_toes.L’
G.bodyBounds = {‘foot.L’: obj[‘bound_ankle.L’], ‘foot.R’: obj[‘bound_ankle.R’], ‘toe.L’: obj[‘bound_toes.L’], ‘toe.R’: obj[‘bound_toes.R’], ‘shin.L’: obj[‘bound_Shin.L’], ‘shin.R’: obj[‘bound_shin.R’], ‘thigh.L’: obj[‘bound_thigh.L’], ‘thigh.R’: obj[‘bound_thigh.R’], ‘hips’: obj[‘bound_pelvis’], ‘spine’: obj[‘bound_abs’], ‘chest’: obj[‘bound_chest’], ‘neck’: obj[‘bound_neck’], ‘head’: obj[‘bound_head’], ‘upper_arm.L’: obj[‘bound_bicep.L’], ‘forearm.L’: obj[‘bound_foreArm.L’], ‘hand.L’: obj[‘bound_hand.L’], ‘upper_arm.R’: obj[‘bound_bicep.R’], ‘forearm.R’: obj[‘bound_foreArm.R’], ‘hand.R’: obj[‘bound_hand.R’]}

#these are the game objects that are used as targets for the bounding rigid bodies, I call them taregts because we are
#taking the bounding body parts and pushing them into the targets place, the target actually is parented to it’s respective bone, therefore we can copy the targets transforms, because they are the same as the bone
G.actionTarget = {‘foot.L’: obj[‘foot.L.Target’], ‘foot.R’: obj[‘foot.R.Target’], ‘toe.L’: obj[‘toe.L.Target’], ‘toe.R’: obj[‘toe.R.Target’], ‘shin.L’: obj[‘shin.L.Target’], ‘shin.R’: obj[‘shin.R.Target’], ‘thigh.L’: obj[‘thigh.L.Target’], ‘thigh.R’: obj[‘thigh.R.Target’], ‘hips’: obj[‘pelvis.Target’], ‘spine’: obj[‘spine.Target’], ‘chest’: obj[‘chest.Target’], ‘neck’: obj[‘neck.Target’], ‘head’: obj[‘head.Target’], ‘upper_arm.L’: obj[‘upper_arm.L.Target’], ‘forearm.L’: obj[‘forearm.L.Target’], ‘hand.L’: obj[‘hand.L.Target’], ‘upper_arm.R’: obj[‘upper_arm.R.Target’], ‘forearm.R’: obj[‘forearm.R.Target’], ‘hand.R’: obj[‘hand.R.Target’]}

#the strength values for each bone, call for example G.jointStrength[‘shin.R’] and it will return 5
G.jointStrength = {‘foot.L’: 2, ‘foot.R’: 2, ‘toe.L’: 1, ‘toe.R’: 1, ‘shin.L’: 5, ‘shin.R’: 5, ‘thigh.L’: 7, ‘thigh.R’: 7, ‘hips’: 10, ‘spine’: 6, ‘chest’: 1, ‘neck’: 3, ‘head’: 6, ‘upper_arm.L’: 4, ‘forearm.L’: 3, ‘hand.L’: 2, ‘upper_arm.R’: 4, ‘forearm.R’: 3, ‘hand.R’: 2}

pelvis = G.bodyBounds[‘hips’]
Control = 1

def animate_rig(cont):

#bodyPart is going to be a string value, we can then take this string, 
#which will be the name of a body part, we can use it to pull values from
#our dictionaries, 
#so let's say the first body part is 'toe.L', we can get
#the toe's bounding object (the actual rigid body game object) by calling
#G.bodyBounds[bodyPart] since bodyPart in this case equals 'toe.L' it will
#return the toe.L bounding game object
#We can then do the same thing to get the actual bone, and the strength of
#the bone by calling our other dictionaries 
for bodyPart in G.bonesList:
    
    #this is the strength value
    strength = G.jointStrength[bodyPart]
    
    #this is the bounding game object for the body part
    bound = G.bodyBounds[bodyPart]
    
    #this is the orientation of the bounding game object for the body part
    boundOrient = bound.worldOrientation
    
    #this is the game object that is parented to the bone, this is where we 
    #will get the bone's transforms from
    target = G.actionTarget[bodyPart]
    
    #this is the orientation of the 'target' game object
    targetOrient = target.worldOrientation
    
    #here we'll do some math with the tartet object and bounding object orientations
    orientCombo = Vector((targetOrient * boundOrient.inverted()).to_euler()) 
    
    #this gets the magnitured of the result from oreintCombo
    magni = orientCombo.magnitude
    
    #I call this speed because originally it was called 'vel' which I assume means velocity
    #and so I thought speed was appropriate
    speed = orientCombo * strength * (Control*20)*magni
    
    #this is the angular velocity of the bounding game object
    angular = bound.worldAngularVelocity.copy()
    
    #setting the world angular velocity of the bounding game object
    bound.worldAngularVelocity = ((angular)+speed)*.5
    
    #this is the new world linV of the bounding object
    boundSpeed = bound.worldLinearVelocity
    
    #this sets the worldLinearVelocity of the bound game object
    bound.worldLinearVelocity=(bound.worldLinearVelocity*.75)+pelvis.worldLinearVelocity*.245
    
    #this gets the new world angular velocity of the bounding game object
    boundAngular = bound.worldAngularVelocity.copy()
    
    #sets the world angular velocity of the bound object
    bound.worldAngularVelocity=(bound.worldAngularVelocity*.95)+pelvis.worldAngularVelocity*.05
    
    #sets the world angular Velocity of the pelvis bounding game object
    pelvis.worldAngularVelocity= boundAngular*.05+ pelvis.worldAngularVelocity*.945

copy and paste that script into your file, turn on colors and lines to make it easier to read, this should help you get a better understanding of what the script is doing. I did this for you quickly because I have to go tend to my life obligations lol. When I get some more free time I’ll implement your original code into my setup and unlock everything and send you that file. But for now maybe this will help you track objects and variables down

I think I see,

you need .worldLinearVelocity.copy() in a few cases
boundSpeed,
but we will see,

same with worldAngularVelocity.copy()

I’ll see what happens in a minute when I get a chance.

Ok scratch that, your bone tag in the spines are wrong

Orientation of each tag needs to match each bone :smiley:

Im away from my pc, on my phone, what do you mean by bone tag in the spines?

orientation of each of the target cubes that are parented to each bone needs to match their respective bone?

Done -

the bone tags were not oriented to the bones !

working!

http://theorysend.com/view/bbca67ca307383f4acb702b2abda91acaf61a46f

Be sure to Credit Jackii , it was his math that I modified (it had no momentum)

:smiley:

Next your going to want to start slower, and work to that kind of walk,

your going to want to use rays or collision sensors on the feet, and check when they are on the
ground vs what animation and frame your playing, or use some fancy vector math,

but the important thing, is the body must move forward , (rigid body chains don’t transfer energy like muscle chains do)

edit - Start walk animation in cross pose = reason = when starting walk the actor does not ‘Trip up’

edit 2 - make sure to overdoo the lift on the step, since momentum is part of the equation, the walk
tries to match, but does not, a higher knee lift will solve to drag issues

edit 3


Psudocode
while animationFrame>=(contact frame left foot) and  animationFrame<=(remove contact frame left foot):
    for parts in ragdoll apply Force (forward vector)


while animationFrame>=(contact frame right foot) and  animationFrame<=(remove contact frame right foot):
    for parts in ragdoll apply Force (forward vector)

thank you jacob, I would’ve gotten back to you sooner but my job is a time suck. I will credit jackii and you whenever this rig makes an appearance anywhere. Im at work but Im gonna take a quick look at what you’ve got