Rouge bodies - I think I understand

Official forum for the Chipmunk2D Physics Library.
Post Reply
gryphon
Posts: 2
Joined: Tue Apr 24, 2012 10:43 am
Contact:

Rouge bodies - I think I understand

Post by gryphon »

I think I finally understand the documentation but let me check. If I want moving objects that are not simulated but I control then I create a body that I don't add to the space and and shape that I do add to the space. I can then control the position by directly setting the position (and velocity?) of he body. Like this:

Code: Select all

 // Should it be static? Doesn't seem like it needs mass and stuff
cpBody*  theBody = cpBodyNewStatic(); 

// Verts for a rectangle
cpVect verts[] = { ... };
cpShape* theShape = cpPolyShapeNew(theBody, 4, verts, cpvzero);

// Don't use cpSpaceAddStaticShape?
cpSpaceAddShape(theSpace, theShape);
When updating:

Code: Select all

cpBodySetPos(theBody, newPos);
Should I use cpBodySetVel too so the stepper can do collision more accurately or should I update the position manually in the stepper loop?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Rouge bodies - I think I understand

Post by slembcke »

Static bodies are a special type of rogue body that never move. Most of the time you want to create a rogue body with infinite mass and moment of inertia. This way it cannot be affected by collisions, and you don't need to figure out what to do about it if it was.

You should update both the velocity and position. If you only update the position, then the object will "teleport" each frame. Things that collide with it will act as though the rogue object wasn't moving at all. Then the next step when the rogue object teleports again, the collisions will look really odd. Either causing popping, mushy collisions, or objects that squeeze through one another.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
gryphon
Posts: 2
Joined: Tue Apr 24, 2012 10:43 am
Contact:

Re: Rouge bodies - I think I understand

Post by gryphon »

Ok I get it. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests