-
Professional Air Guitarist
Verlet Integration / Ragdoll Physics
I'm sure many people are interested in this stuff, so I've made its own thread Here is what I (with some help from Raigan aka metanet) have done in the last few days with this awesome engine:
[EDIT]The examples are now in the LAB section of my site[/EDIT]
Some use the mouse for interactivity, others with the arrowkeys. Most (all?) of the examples are unstable, but still play-with-able.
Let's continue the angle constraint discussion here, metanet.
Last edited by Frag; 12-20-2004 at 02:49 PM.
-
hey,
i'm going to be crazy busy until the end of the weekend
but, nice stuff as usual.
raigan
p.s - i'm really raigan "from" metanet; there are two of us, but one of us (not me) has a more demanding day job and thus doesn't have time to kill on forums
-
Professional Air Guitarist
I see...
One more day until Christmas break! Then I can kill 2 weeks in the forums
-
Senior Member
Originally posted by Frag
I see...
One more day until Christmas break! Then I can kill 2 weeks in the forums
YAY, me too! I seriously hope people post a lot because I will have nothing else to do except read the boards (inside a resort in Mexico)
But anyway, cool links
-
Professional Air Guitarist
I'm surprised no one is interested in this stuff
Over 100 views, and just a couple replies!
-
I think it's awesome! I'd love to play around with it but, I'm afraid it's over my head . . . .
Is there sample code that I could cut n paste?
-
Professional Air Guitarist
code:
Stage.scaleMode = "noScale";
Stage.showMenu = false;
_global.sW = 600;
_global.sH = 400;
this.createEmptyMovieClip("pen", 0);
function getDistance(ob0, ob1) {
return Math.sqrt(Math.pow(ob0.x-ob1.x, 2)+Math.pow(ob0.y-ob1.y, 2));
}
function getMean(values) {
mean = 0;
for (i=0; i<values.length; i++) {
mean += values[i];
}
return mean/values.length;
}
function reset() {
delete _root.onEnterFrame;
drag = .9;
grav = .5;
pL = [];
pL[0] = {x:0, y:0, r:10};
pL[1] = {x:0, y:10};
pL[2] = {x:0, y:60};
pL[3] = {x:0, y:100};
pL[4] = {x:0, y:140};
pL[5] = {x:0, y:50};
pL[6] = {x:0, y:80};
for (i=0; i<pL.length; i++) {
p = pL[i];
if (p.r == undefined) {
p.r = 0;
}
p.ox = p.x;
p.oy = p.y;
}
sL = [];
sL[0] = {p0L[0], p1L[1], w0:.5, w1:.5, col:true};
sL[1] = {p0L[1], p1L[2], w0:.5, w1:.5, col:true};
sL[2] = {p0L[2], p1L[3], w0:.5, w1:.5, col:true};
sL[3] = {p0L[3], p1L[4], w0:.5, w1:.5, col:true};
sL[4] = {p0L[1], p1L[5], w0:.5, w1:.5, col:true};
sL[5] = {p0L[5], p1L[6], w0:.5, w1:.5, col:true};
for (i=0; i<sL.length; i++) {
s = sL[i];
s.rL = getDistance(s.p0, s.p1);
}
_root.onEnterFrame = function() {
if (Key.isDown(Key.SPACE)) {
reset();
}
movePoints();
Verlet();
collide();
drawIt();
};
}
function movePoints() {
if (Key.isDown(Key.UP)) {
pL[0].y -= 10;
}
if (Key.isDown(Key.DOWN)) {
pL[0].y += 10;
}
if (Key.isDown(Key.LEFT)) {
pL[0].x -= 10;
}
if (Key.isDown(Key.RIGHT)) {
pL[0].x += 10;
}
}
function Verlet() {
for (i=0; i<pL.length; i++) {
p = pL[i];
ox = p.ox;
oy = p.oy;
px = p.ox=p.x;
py = p.oy=p.y;
d = pl[i].drag;
p.x += drag*(px-ox);
p.y += drag*(py-oy)+grav;
}
for (i=0; i<sL.length; i++) {
s = sL[i];
p0 = s.p0;
p1 = s.p1;
dx = p0.x-p1.x;
dy = p0.y-p1.y;
d = getDistance(p0, p1);
d0 = d1=(d-s.rL)/d;
d0 *= s.w0;
d1 *= s.w1;
p0.x -= dx*d0;
p0.y -= dy*d0;
p1.x += dx*d1;
p1.y += dy*d1;
}
}
function collide() {
for (i=0; i<pL.length; i++) {
p = pL[i];
if (p.x<p.r) {
p.x = p.r;
}
if (p.x>sW-p.r) {
p.x = sW-p.r;
}
if (p.y<p.r) {
p.y = p.r;
}
if (p.y>sH-p.r) {
p.y = sH-p.r;
}
}
}
function drawIt() {
pen.clear();
pen.lineStyle(5, "0x0000FF");
for (i=0; i<sL.length; i++) {
s = sL[i];
p0 = s.p0;
p1 = s.p1;
pen.moveTo(p0.x, p0.y);
pen.lineTo(p1.x, p1.y);
}
pen.lineStyle(1, "0xFF0000");
pen.moveTo(0, 0);
pen.lineTo(sW, 0);
pen.lineTo(sW, sH);
pen.lineTo(0, sH);
pen.lineTo(0, 0);
}
reset();
Here is a simplified (I know what you're thinking ) version of the body test without circle collision or angle constraints.
-
Oooh Nice!
-
Professional Air Guitarist
Arg, the vB code messed it all up...
-
Man, this is the hot shizzle. I like it alot, keep working on this. BTW: I also wanted to know Frag, how's that old 'Stick' platformer coming along?
-
one BAD mutha FK'er
i'd really like to see it applied, it seems to be promising.
i like how the for the body test, the guy kind of floats around - add in some clouds or something bouncy and it'd work great. the 2nd bike one looks good two, maybe for a lunar gravity kind of rover game or something.
keep going with it.
a little bit of imagination goes a long way...
www.asobiproductions.com
-
Professional Air Guitarist
Originally posted by adit_ya_sharma
Man, this is the hot shizzle. I like it alot, keep working on this. BTW: I also wanted to know Frag, how's that old 'Stick' platformer coming along?
I haven't touched Doodle in a long time, but I think I'm going to finish it over the break.
The possibilities are endless with this thing! I was thinking of making a 2D Halo type game where you drive the vehicle and marines will gun down enemies, or vice versa.
-
Where is the source for this engine?
-
Professional Air Guitarist
-
Professional Air Guitarist
Looky, looky!!!
http://www.gotcool.com/flash/?title=...ovieHeight=400
Raigan, I kinda *cough* borrowed your wheel spinny code. Too many headaches trying to figure it out myself
-
SaphuA
Very very nice work Frag! This engine realy seems to have a lot of possibilities! Keep up the good work Gotta go to school now, will look through the rest of the thread when I'm back home.
-
np -- it's nice that someone actually used the stuff!
i don't suppose you know how to get brakes working
i kind of ran out of time trying to get that working..
raigan
-
Professional Air Guitarist
http://www.gotcool.com/flash/?title=...ovieHeight=400
Press DOWN for rear brakes.
I can't get the wheels to stop (or even slow) while they're suspended above the ground as they would in nature. Any thoughts?
-
nice!!
um.. well, my problem with all of this is that i'm not convinced i really understand what the hell my code does
the "real" way to apply brakes, i think, would be to increase the drag on the particles simulating the wheels -- the drag increases as the particle speed increases. this should work in air and on ground.. the problem i had was that it would stop the wheels from spinning, but then (when later processing collision with the ground) the collision would move the wheels.
you _could_ just add (after collision) a force which cancels out the spin given by collision. but it seems like.. the more hacky conpensating forced we add, the harder it's going to be to find the "real" way to do it.
hm, wait -- the thing i said about drag: it only opposes currenty velocity. really what we want to do is:
-reduce current velocity
-make it harder for the wheel to gain new velocity
the second thing seems to suggest that, when applying torque (from collisions with the ground or whatever), you could use a "weight" on the wheel particles.
uh.. anyway.. right now i'm trying to understand exactly what an inertia tensor is, which is related to all this since it describes how hard it is to spin something. so hopefully i'll have an actual idea soon...
raigan
-
Hey its a year later did you find out ??
I know what it is. a 3x3 matrix which describes the distribution of mass around the three axis of a 3D Body . used when applying correct angular motion.
BUT HOW DO YOU CALCULATE IT ...... HELP !!!
I hope you found out .... otherwise .... it could take me a year not to find out tOOOO!!!!
Shipstern
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|