Bounds Question

Official forum for the Chipmunk2D Physics Library.
Post Reply
jalexander
Posts: 2
Joined: Wed Oct 10, 2012 12:08 pm
Contact:

Bounds Question

Post by jalexander »

Hi - I've created a test application, a game, that uses the chipmunk library to simulate balls bouncing inside a container. The library was really easy to get in the project and use but I'm having some problems understanding how to tune it. This is in Objective-C/XCode on OSX.

So what I have done is to create a space with bounds and some circle shapes that when given some velocity hit the walls and bounce around, and that seems to work great. I am drawing the circles by creating a CALayer centered on the circle shape, and drawing a circle with the same radius as the shape. And this seems to work fine until you observe closely the point at which the circle bounces off the space boundary. It appears that the drawn circle and the circle shape have different radii. And the difference in radius between the two seems to either be different in each instance or depend on the speed at which the circle is traveling. Maybe both I'm not sure. But something very funky is definitely happening with some circles hitting the wall before others, even though the wall is the same for all shapes.

The only thing I can figure is that maybe circle shapes' radii are not defined in pixels and there is some translation that has to occur when drawing. My goal is to have perfect circles of different radius bounce off a wall, and not look like some circles bounce while partially embedded in the wall, and other bouncing before they touch the wall. My gut tells me i'm missing something basic but I can't seem to figure it out. Does anybody have any idea what might be going on?

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

Re: Bounds Question

Post by slembcke »

I think you are noticing that Chipmunk doesn't support swept collisions. Basically, when you call cpSpaceStep(...) it moves all of the objects forward and then checks if they are overlapping. If they are moving too fast, they can end up overlapping other things a lot. The issue can be made much worse if you use variable sized timesteps (i.e. cpSpaceStep(time - lastTime)).

It's recommended to use a fixed timestep, like described in this article: http://gafferongames.com/game-physics/f ... -timestep/ If you have very fast moving objects, you can use a smaller timestep to reduce the amount of overlap. Normally 1/60s is fine, but for fast action games like racing I usually use 1/120 or 1/180. This can end up increasing the smoothness and quality of the simulation too. You have to experiment a bit to find the sweet spot.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 35 guests