Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » Ragdoll System for 2D Platformer

This thread is locked; no one can reply to it. rss feed Print
Ragdoll System for 2D Platformer
Dario ff
Member #10,065
August 2008
avatar

I´ve decided to take the hard path of putting ragdoll characters in my 2d side scroller platformer. I have a good physics engine that has been able to take the task properly, and has performed flawlessly til now.

Ragdoll characters are no easy task when it comes to bringing them to life in a game. The first time I saw Half Life 2, I was amazed to look at the detailed animations of the characters, and seeing them die was a lot of fun too, and it´s one of the things that inspired me to add this system to the game.

The game involves a lot of inmersion in the physics engine, and having prerendered characters wouldn´t be good for the engine. Also, the ragdoll physics might contribute HEAVILY into gameplay(I found myself playing like an hour just tossing a ragdoll into the air, and looking how they move :))

Now, I´ve recently finished an animation editor for the ragdolls. Since I´m getting so deep on this, I would like to see some other examples of this, or hear opinions and suggestions of the good people of Allegro.cc ;D

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

gnolam
Member #2,030
March 2002
avatar

Now, I´ve recently finished an animation editor for the ragdolls.

If they have non-procedural animation, they're not ragdolls. Ragdoll physics is a separate concept from skeletal animation.

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Dario ff
Member #10,065
August 2008
avatar

When the characters die, they become like any other object in the world, and they ARE ragdolls. The Animations are forces and torques that are directly applied to the limbs of characters, so the limbs won´t penetrate on solid objects(like terrain).

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

OnlineCop
Member #7,919
October 2006
avatar

[soapbox]

Your characters should have some kind of skeletal system in place. By itself, that will prevent the arms and legs from extending into positions not "humanly possible" (or "alienly possible", or "robotically possible"), such as bending backward at the joint, dislocating from the joint, etc.

Each joint will need to have a default "force" (I forget the actual term used in industry... tip of my tongue...) which is applied during normal use. That force keeps the character upright, and also returns that character to its "not affected by outside forces" position.

Typically (for humans), that means the character is standing, feet slightly apart, arms dropped to the sides, head upright, and fingers not "clenched" into fists.

When the character is given an action, the action dictates where the hands, elbows, etc. need to "go" and the actual "force" on each joint has to be adjusted so it can carry out that movement. A call to raise_left_hand() would determine that the hand is currently at the character's side (default position), and so the shoulder must rotate n-degrees, the elbow must extend "just a little more", the wrist must rotate m-degrees, and the fingers must straighten.

For "realism" purposes, if the character lifts its hand and finds it under a box it needs to lift, extra "force" is necessary to do so. If this exceeds the character's strength (combined values of all the character joint's "max force" limits), the box doesn't move. If it is light enough that the character can lift it, the forces necessary to lift the box are added, starting from the top (hands/fingers) and working their way down (toward the legs/feet).

Example:

Box weighs 20 pounds. The wrists "max out" at 7 pounds apiece (20 lbs - 2*7 lbs == 6 lbs), so the elbows (which can hold up to 15 pounds apiece) need to be used in order to get the box up.

Another box weighs 200 pounds.

  total_force_needed =
    (wrist[0].max_force + wrist[1].max_force)       // 7 apiece == 14
  + (elbow[0].max_force + elbow[1].max_force)       // 15 apiece == 30, 14+30 == 44
  + (shoulder[0].max_force + shoulder[1].max_force) // 50 apiece == 100, 44+100 == 144
  + (torso.max_force)                               // 30, 144+30 == 174
  + (leg[0].max_force + leg[1].max_force)           // 80 apiece == 160, 174+160 == 334 (which is > 200)

As you can see, you don't need to get your legs involved if you can simply lift the object with your hands and arms, but you DO if your hands, arms, etc. aren't sufficient by themselves.

So if the box is too heavy, your joints will simply be insufficient to move it (you are now crushed under a boulder).

When ragdoll comes into effect, you simply drop all of the forces of the character's joints to 0. Any item grasped in the fingers will be released (some previous force had to have been applied to keep them "closed"), legs will buckle, shoulders will go limp, and all of the parts of the body will have the full force of gravity (or water, or wind) take over.

[/soapbox]

gnolam
Member #2,030
March 2002
avatar

When the characters die, they become like any other object in the world, and they ARE ragdolls.

Then they become ragdolls, yes. But not while they're animated - the whole term "ragdoll physics" stems from the limpness of rag dolls.

Quote:

The Animations are forces and torques that are directly applied to the limbs of characters, so the limbs won´t penetrate on solid objects(like terrain).

Could you explain that a bit more?

OnlineCop said:

Your characters should have some kind of skeletal system in place. By itself, that will prevent the arms and legs from extending into positions not "humanly possible" (or "alienly possible", or "robotically possible"), such as bending backward at the joint, dislocating from the joint, etc.

Do add joint constraints, but "some kind of skeletal system" will not in any established use of the term prevent impossible movements. :P



And damn you, now I have the Diablo Swing Orchestra song in my head again. >:(

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Arthur Kalliokoski
Second in Command
February 2005
avatar

OnlineCop said:

that will prevent the arms and legs from extending into positions not "humanly possible" (or "alienly possible", or "robotically possible"), such as bending backward at the joint, dislocating from the joint, etc.

Seems to me that would easily be possible, as forces greater than the human body can withstand is what turned them into unconscious ragdolls in the first place. I'm replaying GTA3 where you can blow the limbs or head off of pedestrians with high powered rifles.

They all watch too much MSNBC... they get ideas.

Epsi
Member #5,731
April 2005
avatar

Funny that you meantion that, I've just posted a video of my own ragdoll system for Little Gamers:

video

It's using Farseer for the physics and IceCream for rendering and skeletal animation

edit:
IceCream's Editor for CompositeEntity (skeletal anims):
{"name":"littlegamersconcept.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/c\/bcdd3793ba8b418b42188a006f290264.png","w":922,"h":699,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/c\/bcdd3793ba8b418b42188a006f290264"}littlegamersconcept.png

Animation: (playback is too fast, an avi2gif issue)
{"name":"LG_Walk_Prototype.gif","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/8\/c8eac1f2176062cd0e7afc0ee0ff3e96.gif","w":290,"h":190,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/c\/8\/c8eac1f2176062cd0e7afc0ee0ff3e96"}LG_Walk_Prototype.gif

___________________________________

piccolo: "soon all new 2d alegro games will be better. after i finsh my MMRPG. my game will serve as a code reference. so you can understand and grab code from."
piccolo: "just wait until my invetion comes out its going to take the wii to the next leave of game play. it will run sony and microsoft out of busness if i dont let them use it aswell."

Neil Walker
Member #210
April 2000
avatar

Epsi said:

It's using Farseer for the physics

How does that compare to Box2D? I read somewhere that it was based on box2d but ported for .NET, but there is an xna port for box2d now...

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Epsi
Member #5,731
April 2005
avatar

The current version was custom made, and is quite nice so far.

The next version will use Box2D (the current XNA port of Box2D is far from optimized, especially for XBOX).

___________________________________

piccolo: "soon all new 2d alegro games will be better. after i finsh my MMRPG. my game will serve as a code reference. so you can understand and grab code from."
piccolo: "just wait until my invetion comes out its going to take the wii to the next leave of game play. it will run sony and microsoft out of busness if i dont let them use it aswell."

Paul whoknows
Member #5,081
September 2004
avatar

Epsi, what is that music in your video?

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

Epsi
Member #5,731
April 2005
avatar

Epsi, what is that music in your video?

Press the "Statistics" link at the bottom of the video:

Artist:
Chopin Music Box
Song:
Nocturne In B Flat Minor
Album:
Music Box Classics Vol. 1
Time:
08:09
Genre:
Classical
Label:
J

It's a free music provided by YouTube, using their AudioSwap feature :)

___________________________________

piccolo: "soon all new 2d alegro games will be better. after i finsh my MMRPG. my game will serve as a code reference. so you can understand and grab code from."
piccolo: "just wait until my invetion comes out its going to take the wii to the next leave of game play. it will run sony and microsoft out of busness if i dont let them use it aswell."

Dario ff
Member #10,065
August 2008
avatar

Nice video Epsi, It´s a great reference. I´m translating my whole engine to Box2D now, so I have no videos availble, But I´ll try to use longer limbs with my ragdolls. It makes grabbing and tossing them around really fun.

But a little question... what´s the best approach for flipping the ragdoll? Box2D lacks Rotation in another axis, so will I have to "cheat" the positions for getting everything in the right place?

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Epsi
Member #5,731
April 2005
avatar

what´s the best approach for flipping the ragdoll? Box2D lacks Rotation in another axis, so will I have to "cheat" the positions for getting everything in the right place?

Why would you flip a ragdoll? Once it's been spawned you just let it live by itself for death animations, there should be no reason to mirror it to the left.

But for the character collision detection itself in non-ragdoll mode (skeletal animation instead), I just use a dumb rectangle, which doesn't need to be flipped alongside the graphics.

___________________________________

piccolo: "soon all new 2d alegro games will be better. after i finsh my MMRPG. my game will serve as a code reference. so you can understand and grab code from."
piccolo: "just wait until my invetion comes out its going to take the wii to the next leave of game play. it will run sony and microsoft out of busness if i dont let them use it aswell."

Dario ff
Member #10,065
August 2008
avatar

Epsi said:

But for the character collision detection itself in non-ragdoll mode (skeletal animation instead), I just use a dumb rectangle, which doesn't need to be flipped alongside the graphics.

The reason I´m asking is because my characters are ragdolls even when they are alive. But if in the future this becomes too tedious, I will make them use skeletal animations. Thanks for the advice people ;D

TranslatorHack 2010, a human translation chain in a.cc.
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Go to: