Objects Rocking for No Reason

Official forum for the Chipmunk2D Physics Library.
Post Reply
Alekis
Posts: 4
Joined: Thu Feb 14, 2008 5:42 pm
Contact:

Objects Rocking for No Reason

Post 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
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Objects Rocking for No Reason

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Kingdom Of Fish
Posts: 21
Joined: Sun Jan 27, 2008 10:56 am
Contact:

Re: Objects Rocking for No Reason

Post by Kingdom Of Fish »

hmm... this feels familiar...
Alekis
Posts: 4
Joined: Thu Feb 14, 2008 5:42 pm
Contact:

Re: Objects Rocking for No Reason

Post 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.
Blue Prawn
Posts: 22
Joined: Thu Jan 03, 2008 1:36 pm
Contact:

Re: Objects Rocking for No Reason

Post 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.
Alekis
Posts: 4
Joined: Thu Feb 14, 2008 5:42 pm
Contact:

Re: Objects Rocking for No Reason

Post 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.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Objects Rocking for No Reason

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Alekis
Posts: 4
Joined: Thu Feb 14, 2008 5:42 pm
Contact:

Re: Objects Rocking for No Reason

Post 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
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Objects Rocking for No Reason

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: Heise IT-Markt [Crawler] and 8 guests