Ragdoll center of gravity

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
grobi
Posts: 34
Joined: Wed Sep 23, 2009 5:47 pm

Ragdoll center of gravity

Post by grobi »

Hi there,
what I want wo achive is a "controlable" ragdoll which autobalances itself.
Controlable in a way so that I can move the ragdolls limbs by setting a goal on a motor assigned to a joint to rotate or raise its arms, legs...
So far thats working BUT the hard work starts now, the autobalancing of the ragdoll.
By autobalancing I mean, if I make the doll rotate its left leg forward, it wont just fall flat on its face because of gravity, something like it would make its right ankle lean to one side or if thats not enough adjust its right hip or stick out an arm till its back in a steady stance and wont tip over. To do this I figured, I would need to get the center of gravity of the ragdoll and keep it in the "middle", so I will know in which way the center of gravity has to shift till its "OK" again.
But I don't know how... I need help or a slight hint how to determine the ragdolls current center of gravity.

THX
Grobi
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Ragdoll center of gravity

Post by Norbo »

The center of mass can be computed from a weighted sum of all constituent entity positions. For example:

Code: Select all

float accumulatedMass = 0;
Vector3 accumulatedPosition = new Vector3();
foreach (var entity in ragdollEntities)
{
    accumulatedMass += entity.Mass;
    accumulatedPosition += entity.Mass * entity.Position;
}
Vector3 ragdollCenterOfMass = accumulatedPosition / accumulatedMass;
By the way, regarding autobalancing- depending on the degree of realism you seek, that can get Extremely Tricky. Unless the whole point of the project is a physical autobalancing simulation like sumotori dreams or maybe a research project, it's probably worth faking almost all of the 'balancing'. For example, there could be a dedicated constraint keeps the body roughly where it's supposed to be, while animations make it look like the motors are doing something useful.
grobi
Posts: 34
Joined: Wed Sep 23, 2009 5:47 pm

Re: Ragdoll center of gravity

Post by grobi »

Thanks a lot Norbo!
Yeah I thought that "real" autobalancing will be very tricky, too.
The dedicated constraint thing might be the answer.
The overall goal fo the project is to build a fighting simulation like toribash but a lot easier and improved.
Imagine u have a cool robot like fighter or so, "teach" it some cool moves and let it fight against others, during the fights the player can control the movement like sidestep or walk forward, jump, jump backwards etc. and the execution of fight moves. Or a ai script could control these things. The moves teaching would be like an animationeditor where u can set the different motor goals of the ragdolls joints per "frame".
To do this without a little "cheating" would be very very cool, but I think thats more a thing for long boring winter evenings...
grobi
Posts: 34
Joined: Wed Sep 23, 2009 5:47 pm

Re: Ragdoll center of gravity

Post by grobi »

hmm I took a look at the documentation about constraints but didn't figure out yet which one would be best suiteable to keep the ragdoll in place, something like a teleskop stick which can could be made shorter or longer with a ballsocket joint on top which is connected to the center of mass of the ragdoll, preferably at the body/torso. Would this thing than be conneted to another entity which than will be manipulated by forces to make the doll jump or turn and change its postion, or should it be connected to the world ? U see I haven't quite figured it out yet.
Btw. a simple thing but I am doing it wrong. I want to be able to place the ragdoll after creation somewhere in the world and maybe rotate it. I tried this by setting the bodys WorldTransformMatrix which only ended up in only the body itself is rotated everything else is not, or the body turns and pulls everything else connected with it but this kind of twists the whole ragdoll even without gravity influence and not touching the ground.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Ragdoll center of gravity

Post by Norbo »

hmm I took a look at the documentation about constraints but didn't figure out yet which one would be best suiteable to keep the ragdoll in place, something like a teleskop stick which can could be made shorter or longer with a ballsocket joint on top which is connected to the center of mass of the ragdoll, preferably at the body/torso. Would this thing than be conneted to another entity which than will be manipulated by forces to make the doll jump or turn and change its postion, or should it be connected to the world ? U see I haven't quite figured it out yet.
SingleBodyLinearMotor would probably be the most intuitive. It doesn't connect to anything else.

You could also control it just by setting the velocities directly (sort of like a poor man's constraint).
Btw. a simple thing but I am doing it wrong. I want to be able to place the ragdoll after creation somewhere in the world and maybe rotate it. I tried this by setting the bodys WorldTransformMatrix which only ended up in only the body itself is rotated everything else is not, or the body turns and pulls everything else connected with it but this kind of twists the whole ragdoll even without gravity influence and not touching the ground.
Every entity comprising the ragdoll must be moved. Otherwise, part of the ragdoll will be on the other side of the map. The constraints will try to fix that error by pulling the separated parts together which can produce quite an explosion.

So, instead of setting just the body's transform, compute and apply every entity's transform.
grobi
Posts: 34
Joined: Wed Sep 23, 2009 5:47 pm

Re: Ragdoll center of gravity

Post by grobi »

I now attached a SingleEntityAngularMotor to the ragdoll body for rotation and a SingleEntityLinearMotor for movement.
The thing is when I move the ragdoll with he linearMotor it does not reach the goal in a straight line. Its like gravity is pushing it down on its way to the goal and on finish it floats slowly up to the right height. Rotation is almost the same thing.
And thats not working cos while moving, the ragdoll has to float slightly over the the ground since limbs which are touching the ground like the feet will be dragged over it and will change the posture. I tried setting stiffness and damping of the SpringSettings but its just helping a little I ended up with 10000 as value and maximumforce of 1000 of the motors.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Ragdoll center of gravity

Post by Norbo »

Its like gravity is pushing it down on its way to the goal and on finish it floats slowly up to the right height.
Yup. If you want to reduce that effect, increase the damping coefficient and make sure the maximum force is sufficiently high that it can lift the body without interference. For tuning purposes, it's often easiest to keep maximum force at float.MaxValue while tuning the spring settings, then go back and reduce it only if necessary.
grobi
Posts: 34
Joined: Wed Sep 23, 2009 5:47 pm

Re: Ragdoll center of gravity

Post by grobi »

... I found working damping and stiffnes values but in the end I want it more "dynamic" now its really more like a doll on a stick. I think I'm going with the "real physics" aproach. I managed to get some quick and dirty sideways balancing code working, but I think a neural network will do a much better job.
I need to know if the feet or hands are touching the ground (ground is just a static box) what would be the fastest way of doing this? Using collision or casting rays? I want to use this information to create servor motor chains which could be uses fully or partially to balance the ragdoll. So that the ragdoll can reach its pose and can balance itself with the unused axis of the servo motors.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Ragdoll center of gravity

Post by Norbo »

I need to know if the feet or hands are touching the ground (ground is just a static box) what would be the fastest way of doing this?
Collision events or scanning the pairs and contacts of an entity. I often prefer the scanning approach since it can be more direct and you have full control over where/when it executes.

The scanning approach looks like this:
For each pair in entity.CollisionInformation.Pairs, check if one of the entities (EntityA or EntityB, note that they are not ordered) is the one you care about, and check if the pair.Colliding property is true.
Post Reply