Changing shapes and collisions

Official forum for the Chipmunk2D Physics Library.
Post Reply
jeapostrophe
Posts: 13
Joined: Thu Jul 23, 2009 7:54 am
Contact:

Changing shapes and collisions

Post by jeapostrophe »

I have a platform character standing on a line and I am changing the collision shape to match the next animation.

First, I remove the old shapes from the space.
Second, I add all the new shapes to the space.

However, the next time I step the space, the body falls through the floor and doesn't interact with anything, but does move.

I've experimented by creating the shapes afresh, but that doesn't fix it. Nor did drastically increasing iterations. Nor did cpResetShapeIdCounter.

Any example code or pointers?

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

Re: Changing shapes and collisions

Post by slembcke »

Think about what you are doing in a real world sense. Your character is being instantly removed and rematerialized with his feet in the ground. Chipmunk has no idea how to handle that. Depending on how deep the new shape is penetrating, it might try to push it out of the ground slowly or maybe just let it fall through. Chipmunk does not support deformable objects and there isn't really a workaround to this.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
jeapostrophe
Posts: 13
Joined: Thu Jul 23, 2009 7:54 am
Contact:

Re: Changing shapes and collisions

Post by jeapostrophe »

To clarify, I never remove the body.

Also I have the same problem if I switch shapes when the player is in the air (ie not penetrating anything). And in that case I can do something really weird: switch the shapes while in the air then switch back and he doesn't fall through. It is weird because they are just as new shapes even if they are isomorphic to the original.

What do people mean when they say "switch to a more complex shape" on collisions if not this type of thing?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Changing shapes and collisions

Post by slembcke »

Adding or removing shapes on the fly shouldn't break anything, it just might end up not looking like real physics if the objects are already contacting. I'm guessing that the real problem for you is that you have a winding that is backwards on a poly shape or something.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
jeapostrophe
Posts: 13
Joined: Thu Jul 23, 2009 7:54 am
Contact:

Re: Changing shapes and collisions

Post by jeapostrophe »

Life saver! Thanks a ton.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests