Page 1 of 1

Objects Rocking for No Reason

Posted: Thu Feb 14, 2008 8:13 pm
by Alekis
Well, I'm new to Chipmunk physics so there's still a lot I need to figure out. But I've got the library compiling in my own little project, but I'm having an issue with blocks not behaving at all realistically. It's a very simple setup, one long line across the bottom that is unmovable, and two block that fall from the sky on top of it. But for some reason, instead of just falling and landing on the ground, they hit, and then proceed to rock back and forth. It's almost as if they are trying to stand on their points instead of a flat surface. I can't figure out what's causing it.

I'll edit this post and put the link to a 30 second video of the problem once rapidshare finishes uploading my file.

Edit-
http://rapidshare.com/files/91930379/JumpLR.avi.html

Re: Objects Rocking for No Reason

Posted: Fri Feb 15, 2008 2:03 am
by slembcke
What codec is that? Neither VLC or MPlayer could play it.

What are you setting for the moment of inertia? You should be using cpMomentForCircle or cpMomentForPoly to calculate them.

Re: Objects Rocking for No Reason

Posted: Fri Feb 15, 2008 6:04 am
by Kingdom Of Fish
hmm... this feels familiar...

Re: Objects Rocking for No Reason

Posted: Fri Feb 15, 2008 12:32 pm
by Alekis
slembcke wrote:What codec is that? Neither VLC or MPlayer could play it.

What are you setting for the moment of inertia? You should be using cpMomentForCircle or cpMomentForPoly to calculate them.
Hmm, that's odd. I used Fraps to grab it as I'm doing this on my PC. But when I got home I double checked the video on VLC on my mac and it ran it. Do you have the most recent version of VLC? It's possible I grabbed an extra video codec for VLC a while ago and just forgot.

Anyways, I'm using cpMomentforPoly.

Code: Select all

        cpVect verts[] = {
                cpv( 85, 15),
		cpv( 85, 45),
		cpv( 115, 45),
		cpv( 115, 15)
	};
        rbFall = cpBodyNew(5.0, cpMomentForPoly(5.0, 4, verts, cpvzero));
	cpSpaceAddBody(gameSpace, rbFall);
	shFall = cpPolyShapeNew(rbFall, 4, verts, cpvzero);
	shFall->e = 0.0; shFall->u = 1.5;
	cpSpaceAddShape(gameSpace, shFall);
I assume that is all correct?

I'll see if I can get something on Youtube, because it would probably help quite a bit to see the problem in action.

Re: Objects Rocking for No Reason

Posted: Fri Feb 15, 2008 1:03 pm
by Blue Prawn
Why don't you just put your video temporary on your web-area ?
It shouldn't be more than 5Mo, is it ?

For the problem, I suspect that it is the oscillating contact problem.
If it is that case, just grep for "oscillating contacts" in the doc.
Basically try to hack at the gobal vars cp_contact_persistence and cp_collision_slop.

Re: Objects Rocking for No Reason

Posted: Fri Feb 15, 2008 1:11 pm
by Alekis
Well, no need to host it on my own because you can get it from rapid share. It was just an issue with the video codec itself. I'm not sure what Fraps uses.

I did consider that it had something to do with a weird contact like that. But the way these squares are moving is not like that. These squares are rolling from one whole face to another, and there's no jerkiness either. o.O

But thanks for the pointer, I'll try messing with those values anyways and see if it helps.

Re: Objects Rocking for No Reason

Posted: Fri Feb 15, 2008 1:43 pm
by slembcke
Did you intend the center of gravity to be inside the box?

Your poly vertex coordinates are supposed to be local to the body. Not in world coordinates. I think you meant for your coordinates to go from -15 to 15 (x and y). Instead of the 85 to 115 (x) and 15 to 45 (y) you are using. You then move the shape into position by setting the position of the body.

Re: Objects Rocking for No Reason

Posted: Fri Feb 15, 2008 2:04 pm
by Alekis
Oh of course...Ha, wow, yeah that fixed it. Thanks so much!

I was thinking that setting the position myself was completely off-limits. Even though really, I guess that only applies during the actual game loop, not initialization.

Thanks again. Absolutely wonderful library, perfect for what I'm doing. Hopefully this is the last time I have to bother you guys with questions. XD

Re: Objects Rocking for No Reason

Posted: Fri Feb 15, 2008 4:46 pm
by slembcke
Yep. The only issue of setting the position yourself is that it prevents Chipmunk from resolving collisions properly. As long your position changes don't cause objects to overlap or give objects a 'fake' velocity, it's fine. It's pretty much always safe to do during initialization as you aren't compounding the problem by setting the position frame after frame, and it's far less likely to cause intersections.