Page 1 of 1

Changing shapes and collisions

Posted: Wed Jul 29, 2009 12:59 pm
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

Re: Changing shapes and collisions

Posted: Wed Jul 29, 2009 2:00 pm
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.

Re: Changing shapes and collisions

Posted: Wed Jul 29, 2009 2:15 pm
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?

Re: Changing shapes and collisions

Posted: Wed Jul 29, 2009 2:55 pm
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.

Re: Changing shapes and collisions

Posted: Wed Jul 29, 2009 3:02 pm
by jeapostrophe
Life saver! Thanks a ton.