Ragdolls in chipmunk.

Official forum for the Chipmunk2D Physics Library.
scorp
Posts: 29
Joined: Sat May 10, 2008 1:41 pm
Contact:

Re: Ragdolls in chipmunk.

Post by scorp »

I'm actually using C++. I guess my code is so primitive that it looks like C. :lol: :mrgreen:
scorp
Posts: 29
Joined: Sat May 10, 2008 1:41 pm
Contact:

Re: Ragdolls in chipmunk.

Post by scorp »

Wheeee!!!
Now that my function works with pointers instead of actual structures everything is ok.

void adddoll(RagDoll *doll)
{
float BodyLength=doll->BodyLength;
float BodyFat=doll->BodyFat;
float ThighLength=doll->ThighLength;

........................

head = cpBodyNew(0.2, cpMomentForCircle(0.2, 0, abs(SKX)*HeadSize, cpvzero));
head->p = cpv(initX+SKX*(HeadSize/5), initY+SKY*(BodyLength/2+HeadSize));
cpSpaceAddBody(space, head);

........................

doll->head=head;
}

After using that function to create an actual ragdoll

adddoll(player1);

I can adress player1's head (and other parts)

player1.head->t=20000;
or
player1ptr->head->t=20000;

Both ways work just fine.

No trouble with multiple ragdolls too.


I still don't understand why it didn't work without pointers. Pointers always confused me... :oops: :mrgreen:
scorp
Posts: 29
Joined: Sat May 10, 2008 1:41 pm
Contact:

Re: Ragdolls in chipmunk.

Post by scorp »

Even better!

void adddoll(RagDoll *doll)
{
float BodyLength=doll->BodyLength;
float BodyFat=doll->BodyFat;
....................
doll->head = cpBodyNew(0.2, cpMomentForCircle(0.2, 0, abs(SKX)*HeadSize, cpvzero));
doll->head->p = cpv(initX+SKX*(HeadSize/5), initY+SKY*(BodyLength/2+HeadSize));
cpSpaceAddBody(space, doll->head);
}

No need for
doll->head=head line and extra cpBody variables.
scorp
Posts: 29
Joined: Sat May 10, 2008 1:41 pm
Contact:

Re: Ragdolls in chipmunk.

Post by scorp »

Relaxing joints is easy. Extending\contracting joints is also easy (I'l write about that a bit later).

But I just can't think of way to implement holding.

By "holding" i mean:
1) Joints don't move by themselves (unlike extanding\contracting ones).
2) Joints resist being moved (unlike relaxed one).They CAN be moved, but with certain amount of force.
scorp
Posts: 29
Joined: Sat May 10, 2008 1:41 pm
Contact:

Re: Ragdolls in chipmunk.

Post by scorp »

Time to make myself useful for future ragdollers.

Let's say, for example, that you need to contract ragdoll's knee.
Applying torque to shin does the job, but as soon as knee-angle hits the limit torque starts to rotate whole leg and then whole ragdoll.

Solution:
Apply same amount of torque but in different direction to the hip.

Works perfectly, look realistic, very easy to implemet.
That's actually how real joints works - by apply force to both attached body parts.
rd.jpg
Not much of a tip.... :oops: I hope it will be useful for someone.
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests