This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-07-12 00:01:16

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Rag Doll Physics

I guess this is mainly geared towards amcerbu...but I was wondering if anyone has any experience with using rag doll physics?

I'm kind of testing my own method as of now...not very far into it, but basically every body part has two locations (top and bottom) that dictate it's position and direction.  Also each part has a parent object that it inherits the position of and then builds off of for it's final position.  That's about all I have right now.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#2 2012-07-12 00:24:02

zubblewu
Scratcher
Registered: 2011-02-17
Posts: 1000+

Re: Rag Doll Physics

Makes sense. And yeah, amcerbu an you are the two people I'd probably trust most for Something like this XD. I'd suggest a way for it to inherent force from its "child" maybe?


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

Offline

 

#3 2012-07-12 00:41:13

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Rag Doll Physics

Oh, yeah.  That stuff's really hard.  I saw a ragdoll physics article out on the internet awhile ago where "inverse kinematics" was concerned.  The way they explained it, kinematics is the study of determining the location of, say, the hand at the end of the arm, based on the angles of the joints.  Inverse kinematics tries to determine angles for the joints to produce a desired location for the hand.  I'm not exactly sure what that has to do with ragdolls, but you can check out the page for yourself. 

Anyway, here's the link.  Good luck!  Maybe I'll play around with something, but I'm not very hopeful that I'll get anywhere.

Offline

 

#4 2012-07-12 09:53:45

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Rag Doll Physics

amcerbu wrote:

Oh, yeah.  That stuff's really hard.  I saw a ragdoll physics article out on the internet awhile ago where "inverse kinematics" was concerned.  The way they explained it, kinematics is the study of determining the location of, say, the hand at the end of the arm, based on the angles of the joints.  Inverse kinematics tries to determine angles for the joints to produce a desired location for the hand.  I'm not exactly sure what that has to do with ragdolls, but you can check out the page for yourself. 

Anyway, here's the link.  Good luck!  Maybe I'll play around with something, but I'm not very hopeful that I'll get anywhere.

Thanks! Looks like a pretty good article.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#5 2012-07-12 10:14:59

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: Rag Doll Physics

You may find more help in Advanced Topics, even though this is the proper forum  smile


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#6 2012-07-12 13:21:18

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Rag Doll Physics

Wes64 wrote:

You may find more help in Advanced Topics, even though this is the proper forum  smile

Maybe...but I'd rather try and figure it out with someone then just have someone tell me how to do absolutely everything.

Ok, so update on the idea: Position 1 for every part is calculated by the inheritance and what not.  Position 2 is then calculated with this:
Distance = sqrt( (1.x-2.x)^2 + (1.y-2.y)^2)
2.x = 1.x + ( (1.x-2.x)*length)/Distance
2.y = 1.y + ( (1.y-2.y)*length)/Distance
Where length is a predetermined number.  This avoids using trig and rotation which I feel will leave room for vector velocity with x and y components instead of a velocity based off direction and a magnitude.
It could also be used during the inheritance process as well.

Last edited by AtomicBawm3 (2012-07-12 13:34:52)


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#7 2012-07-12 14:37:34

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Rag Doll Physics

^^ I love vectors.  They make trig look so unnecessary.

Offline

 

#8 2012-07-12 14:49:44

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Rag Doll Physics

amcerbu wrote:

^^ I love vectors.  They make trig look so unnecessary.

Lol, yeah...still, trig does have to be used because I'm making the parts out of costumes...but it's minimal, only an arc-tangent really  smile


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#9 2012-07-12 21:05:51

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Rag Doll Physics

Hey amcerbu: would you be able to look at my scripts?  I thought I got it all right, but it doesn't work at all.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#10 2012-07-12 23:49:34

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Rag Doll Physics

Are you talking about the stuff you posted above with distance constraints?  So far, I can't see anything wrong with it. 

A few other questions: what shape are you simulating?  A stickman?  Something more complicated?  Also, how fast do you want this to run? 

And here's an idea for implementation (at least, this is how I'd do it):  Everything is based on a central "source point."  For this project, the lines won't have mass, just the points, and we'll say all masses are equal.  Each point has an "impulse" velocity; the way it wants to travel.  It will try to travel that way.  When it reaches a distance constraint, it projects its velocity onto its constraints; any points it is attached to.  The remaining velocity (the vector "rejection") is given to the point at the other end of the constraint.  You may have to do some recursive stuff to get all the points to affect all the other ones.

If you manage to implement what the guy did in that article I posted, adding velocity won't be terribly difficult.

Offline

 

#11 2012-07-12 23:53:44

1s1sKing
New Scratcher
Registered: 2012-07-12
Posts: 30

Re: Rag Doll Physics

Hmmm. What amcerbu said sounds about right. Just a suggestion, depending on how you want to do this, you could have it be one sprite an one script by stamping each body parts costume, or if it's simple, using the pen.

Offline

 

#12 2012-07-13 00:07:20

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Rag Doll Physics

1s1sKing wrote:

Hmmm. What amcerbu said sounds about right. Just a suggestion, depending on how you want to do this, you could have it be one sprite an one script by stamping each body parts costume, or if it's simple, using the pen.

Yeah...I kind of started out that way, but I decided not to because it's easier sometimes to have calculations shown in separate broadcasts...and I'm running it very slow right now.  Still not working.  I'll upload it tomorrow to my test account and let you look.  It is a human body as well with 10 parts (upper and lower legs and arms, torso, and head).


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#13 2012-07-13 00:14:09

1s1sKing
New Scratcher
Registered: 2012-07-12
Posts: 30

Re: Rag Doll Physics

Hmmm. Broadcasts lag a lot... You might want to build it for turbo mode, or it could end up lagging to much for the regular players, but going to fast in turbo. If you could, putting them in a single script. Since your length is set, you could probably do all the calculations, then render the body parts based on it. I definitely want to see how this turns out  smile
And again, I would reccomend keeping it a single script. It would lag much less. If your computer has trouble with it, save often and put the end of the script in a forever/repeat until block, then insert the second to last smallish segment, etc until your script is done. Alternatively, you could try the clean up scripts button so you just have to go to the bottom and drag the bits in. Can't Wai to see this finished.

Offline

 

#14 2012-07-13 00:18:42

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Rag Doll Physics

Hey, AtomicBawm3: Check out this article

It has some interesting stuff about cloth dynamics and something close to ragdoll physics.  I hope you've had some Calculus in school (or, at least Pre-Calc) because there's stuff about Verlet Integration. 

I'd suggest you read the entire thing; it's pretty cool and you might be able use some of the things they talk about, especially where distance constraints are concerned. 

Gamasutra has some really good articles, so there's probably more out there.

Last edited by amcerbu (2012-07-13 00:19:58)

Offline

 

#15 2012-07-13 00:19:38

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Rag Doll Physics

1s1sKing wrote:

Hmmm. Broadcasts lag a lot... You might want to build it for turbo mode, or it could end up lagging to much for the regular players, but going to fast in turbo. If you could, putting them in a single script. Since your length is set, you could probably do all the calculations, then render the body parts based on it. I definitely want to see how this turns out  smile
And again, I would reccomend keeping it a single script. It would lag much less. If your computer has trouble with it, save often and put the end of the script in a forever/repeat until block, then insert the second to last smallish segment, etc until your script is done. Alternatively, you could try the clean up scripts button so you just have to go to the bottom and drag the bits in. Can't Wai to see this finished.

Again, I'm not going for speed yet, I'm going for accuracy. I'll go for speed once I know it can work at a very slow rate.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#16 2012-07-13 00:26:15

1s1sKing
New Scratcher
Registered: 2012-07-12
Posts: 30

Re: Rag Doll Physics

Ahhhh. Good idea. Another thing I would recommend you add is a little bit of force absorption from each "child". If say the lower arm gets flung, the lower arm should move. I hope I've been helpful  smile

Offline

 

#17 2012-07-13 00:28:55

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Rag Doll Physics

@1s1sKing- "Too fast in Turbo" can be fixed using what I like to call a "framerate" lock; every script is called in sequence with "broadcast _ and wait," and the script waits for the remaining time (I use 1/30 second, or 30 frames/second) before repeating.  This especially prevents flickering in pen projects. 

But, back to the topic, AB3: I'll check out your project in the morning.  I hope you have time to look at the Gamasutra article (I'm never sure whether anyone sees posts when they get buried underneath other ones).

Offline

 

#18 2012-07-13 00:30:56

1s1sKing
New Scratcher
Registered: 2012-07-12
Posts: 30

Re: Rag Doll Physics

@amcerbu I know that. I typically use that when I create a turbo mode project. It's also useful if you create a slider, and can has a user controlled framerate.

Offline

 

#19 2012-07-13 11:11:41

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Rag Doll Physics

Well you guys seem to be having a pleasant conversation  smile .  I figured out my problem by making this...I'll get back to you if the body system starts working.

EDIT: Amcerbu: I might read it...but I hate the layout of the article and it hurts my eyes...thanks though.

Last edited by AtomicBawm3 (2012-07-13 11:14:07)


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#20 2012-07-13 12:23:07

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Rag Doll Physics

I'm checking out your "Pull Line" project right now.

Offline

 

#21 2012-07-13 12:34:35

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Rag Doll Physics

amcerbu wrote:

I'm checking out your "Pull Line" project right now.

Here's the version with gravity and velocity: Link.

Seems to work pretty well!  I think what I'm going to have to do for the body once I'm ready is to have 5 separate pull lines, one for each limb and one for the head/torso.  Then the limb pull lines depend on perpendicular lines that hook into the torso and the torso is dependent on the head which is dependent on the mouse.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#22 2012-07-13 19:45:21

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Rag Doll Physics

I've gotta say, the rope with velocity looks really good.  Perhaps it would be nice if you included an option to adjust friction (or is it hard-coded into your script?).

Offline

 

#23 2012-07-13 22:24:42

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Rag Doll Physics

amcerbu wrote:

I've gotta say, the rope with velocity looks really good.  Perhaps it would be nice if you included an option to adjust friction (or is it hard-coded into your script?).

Currently it is, but I was going to make different values for different parts...maybe.  But yeah, maybe I'll do that.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#24 2012-07-15 15:25:12

AtomicBawm3
Scratcher
Registered: 2009-06-27
Posts: 1000+

Re: Rag Doll Physics

Ok, I'm writing this because I'd like somebody to look over the math for this one final time...clearly I've already got most of the physics figured out, but I needed to figure out how to create offsets for the arms and legs so that they were a tad more realistic.  Here's the math I've come up with that avoids using trig to find a point rotated from any location:
Let's say that you've got a line for the middle of the body in the form y=mx+b based off of the two points at either end of the torso. Info needed:

Length of torso= 40 (for now)
m=(x1-x2)/(y1-y2) (of torso)
Offset on the y-axis (oy)= -4 (again, for now)
Offset on the x-axis (ox)= -10
and of course, x1, x2, y1, and y2

Basically, I'm going to calculate two vectors that are perpendicular to each other where the vector for y uses m and the vector for x uses -1/m.  Vector 1 can be calculated like so:
V1.X = -4(x1-x2)/40
V1.X = (x2-x1)/10

V1.Y = -4(y1-y2)/40
V1.Y = (y2-y1)/10

This vector is simple enough to calculate, but the perpendicular vector took some work:

First, you have to calculate a vector in the correct direction, which is simple enough since we know that a perpendicular line is simply -1/m.  Giving the vector the imaginary points of (x,y) and (x+1,y-1/m) we can clearly see that:
dx = -1
dy = 1/m
so our vector's current distance is sqrt(1/(m^2)+1).  To make the vector the right length, we simply do what I've been doing for all of the point calculations:
(x,y) of vector = (-dx*l/dist, -dy*l/dist)
so our vector becomes:
V2.X = -10/dist
V2.Y = -10/(m*dist)

To get the final position:
Final.X = Start.X + V1.X + V2.X
Final.Y = Start.Y + V1.Y + V2.Y
where Start is point 1.

Anyway...that's probably more confusing than it should be...but it should work.


http://i50.tinypic.com/j0yw0p.jpg

Offline

 

#25 2012-07-15 16:27:36

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: Rag Doll Physics

^^ I don't quite get it.  One piece of advice I can offer, though: the vector perpendicular to <a, b> is <b, -a>.

Offline

 

Board footer