Hi there. I'm just starting out with Chipmunk, and I'm writing my code using the Python wrapper, Pymunk. So far the library looks amazing and is exactly what I was looking for.
I have a certain problem I'd be very grateful if anyone would help me solve.
Consider the following scenario: http://i110.photobucket.com/albums/n110 ... nshot2.jpg
All of the shapes are perfect rectangles. The problem is that they never completely stand still. They seem as if to always move when in contact with one another (the bottom columns seem to always be motionless...), so if I leave that tower alone for a few minutes, most of the shapes (the columns) seem to drift towards the right and finally the whole structure collapses.
The infinite mass and inertia segment that holds the entire structure above it has a friction of 1.5 and an elasticity of 0. The rectangle shapes have the same attributes. I build the tower by adding objects to the space one by one, while the program is running. (For instance, I create a block above another one and it falls down on top of it.)
What am I doing wrong? I'd hate to be known as a George Costanza of the architect world.
Objects constantly move against each other
-
- Posts: 3
- Joined: Sat Aug 23, 2008 7:46 am
- Contact:
-
- Posts: 157
- Joined: Mon Aug 20, 2007 12:53 pm
- Location: London, UK
- Contact:
Re: Objects constantly move against each other
You're probably not doing anything wrong. Stacking objects is difficult to simulate.
But there are things you could do to make it more likely to work. These tips from the docs will probably help:
But there are things you could do to make it more likely to work. These tips from the docs will probably help:
- Use more iterations.
- Use a smaller time step.
- Use a fixed time step. By allowing the contact persistence to work properly, you can use more iterations without increasing the computational cost.
-
- Posts: 206
- Joined: Tue Aug 21, 2007 3:12 pm
- Contact:
Re: Objects constantly move against each other
Sleeping bodies would also help. Someone just have to add them to chipmunk. rje has done it in his actionscript library based on chipmunk: http://www.slembcke.net/forums/viewtopic.php?f=1&t=221 so that would be a good staring point for an experiment like that.
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
-
- Posts: 3
- Joined: Sat Aug 23, 2008 7:46 am
- Contact:
Re: Objects constantly move against each other
Ah, I was afraid this would be something hard to solve. The doc tips only serve to delay everything, the objects still move and the tower will collapse eventually, given enough time. Also, I'll look into that actionscript library. Flash hasn't been one of my strongpoints, but I've never actually given it enough time.
Thanks for the help!
Thanks for the help!
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Objects constantly move against each other
One of my demos (#5) does a very similar pyramid of blocks. I have no issues with stability in that one. It's rock solid stable. I've ran it to thousands of time-steps and the blocks don't shift at all.
As long as you are using fixed size time-steps, the stability should only increase over time as long as you are using enough iterations. If Chipmunk supported sleeping the bodies, it wouldn't help much in the case where the objects never stop moving. Sleeping isn't meant to increase stability, it's to increase speed in sparse or largely static simulations.
As long as you are using fixed size time-steps, the stability should only increase over time as long as you are using enough iterations. If Chipmunk supported sleeping the bodies, it wouldn't help much in the case where the objects never stop moving. Sleeping isn't meant to increase stability, it's to increase speed in sparse or largely static simulations.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 3
- Joined: Sat Aug 23, 2008 7:46 am
- Contact:
Re: Objects constantly move against each other
It looks like I really didn't use enough iterations. The demos cleared some things up. Things are much better now, although the tower does collapse if I build it too high. However, I suspect it's because I'm shaking it up when I slam blocks to the top of it and don't wait, so it becomes more and more unstable. So I really am the George Costanza of the architect world after all.
Again, thanks for the help!
Again, thanks for the help!
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Objects constantly move against each other
Yeah, basically the more layers you add between any one object and a solid object like the ground, the more computationally expensive it becomes and you have to add more iterations to compensate.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 206
- Joined: Tue Aug 21, 2007 3:12 pm
- Contact:
Re: Objects constantly move against each other
I got the impression that demos with sleep in them behaved more stable (like box2d w w/o sleep). Something like the object moves a tiny bit each frame if its not sleeping but with sleep the movement/force on the object is not high enough to unsleep the body. Then this tiny movement builds up frame after frame to eventually affect other objects and for example collapse a tower.. But you are the physics master and I hope I didn't confused anyone with my speculationsslembcke wrote:One of my demos (#5) does a very similar pyramid of blocks. I have no issues with stability in that one. It's rock solid stable. I've ran it to thousands of time-steps and the blocks don't shift at all.
As long as you are using fixed size time-steps, the stability should only increase over time as long as you are using enough iterations. If Chipmunk supported sleeping the bodies, it wouldn't help much in the case where the objects never stop moving. Sleeping isn't meant to increase stability, it's to increase speed in sparse or largely static simulations.
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Objects constantly move against each other
Well sort of...
Every paper that I've read physical simulation that mentioned sleeping has only referred to it as an optimization and not a way to increase stability.
Maybe our ideas of "stable" are different as well. I'm thinking about this from the idea of numerical stability of the simulation. Sleeping does not solve that. Once an object gets woken up again, it will be just as unstable as before if it was creeping for some reason. I'd argue that it can increase the realism of an unstable simulation by reducing the artifacts.
Every paper that I've read physical simulation that mentioned sleeping has only referred to it as an optimization and not a way to increase stability.
Maybe our ideas of "stable" are different as well. I'm thinking about this from the idea of numerical stability of the simulation. Sleeping does not solve that. Once an object gets woken up again, it will be just as unstable as before if it was creeping for some reason. I'd argue that it can increase the realism of an unstable simulation by reducing the artifacts.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Who is online
Users browsing this forum: Bing [Bot] and 32 guests