Joints

Official forum for the Chipmunk2D Physics Library.
Post Reply
kyleroche
Posts: 3
Joined: Fri Dec 16, 2011 5:06 pm
Contact:

Joints

Post by kyleroche »

Hi, I've been reading through similar posts, but I'm still having issues. I'm trying to pin an arm to a static body. At this point, it's just falling off the screen.

This is where I create the static body (it's been changed a few times due to errors and attempts to fix this issue)

Code: Select all

 
    body = cpBodyNew(mass, cpMomentForBox(mass, self.contentSize.width, self.contentSize.height));
    
    body->p = location;
    body->data = self;
    //cpSpaceAddBody(space, body);
    
    shape = cpBoxShapeNew(body, self.contentSize.width, self.contentSize.height);
    shape->e = 0; 
    shape->u = 0;
    shape->data = self;
    //shape->group = 1;
    shape->collision_type = 0;
    cpSpaceAddShape(space, shape);
    
I create a non static body, add it to the space and then pin it as such:

Code: Select all

cpConstraint *josephHandPinJoint = cpPinJointNew(joseph.body, josephHand.body, cpv(114, 107), cpv(0, 0));
cpSpaceAddConstraint(_space, joesphHandPivotJoint);
The hand just falls off the screen. Is there a tutorial or example around that I could follow that shows you how to put a static body on the screen that is not affected by touch or gravity then attach some rotating bodies to it (like arms)?

Thanks. Sorry for the very similar question to others you already have posted.

Kyle
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Joints

Post by slembcke »

You might want to re-read the section on static and rogue bodies here: http://chipmunk-physics.net/release/Chi ... ougeStatic

What you are creating is a rogue body (because it's not added to the space), and it presumably doesn't have infinite mass. An infinite mass rogue body can effectively function as a static body, but real static bodies as created by cpBodyNewStatic() have a special flag set that allow objects to fall asleep when touching them. If your rogue body doesn't have infinite mass and you aren't manually updating it weird stuff will happen.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
kyleroche
Posts: 3
Joined: Fri Dec 16, 2011 5:06 pm
Contact:

Re: Joints

Post by kyleroche »

Hi. Thanks for the quick reply.

Interesting... so, if the body to which i'm pinning the arms will never move, should I just make that a sprite? then ping the arms to the &space->staticBody?

Would that make more sense than what I'm trying to do?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Joints

Post by slembcke »

That would work completely fine yes. It can be convenient to make extra static bodies just for code organizational purposes, but if you can share them that's good too. It would be a little wasteful of memory to make thousands of little shapes, one for each little static shape or joint, but it probably wouldn't affect performance that much.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
kyleroche
Posts: 3
Joined: Fri Dec 16, 2011 5:06 pm
Contact:

Re: Joints

Post by kyleroche »

Thanks again! I pinned it to the &space->staticBody. Much smoother now.

Cheers
Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests