mistake with iterations or time for step ?

Official forum for the Chipmunk2D Physics Library.
Post Reply
User avatar
sja
Posts: 5
Joined: Wed May 13, 2009 4:46 pm
Contact:

mistake with iterations or time for step ?

Post by sja »

Hello, all!

I've got next problem (when running on my iPhone): my boxes behave very strangely - i've set ground (pink on screen), and put boxes to the ground (ground is static object).
Picture 1.png
When i run cpSpaceStep i can see how my boxes shaking, tremble (attached file 2).
Picture 2.png
I'm obtain same result on PC (good CPU) when i gave elapsedTime*2 (or *3, more) to cpSpaceStep.

In my app i've only 30fps, and if i put into cpSpaceStep really 0.033 sec then all works good, but very slow.
If i put into cpSpaceStep 0.6 seconds, then speed is very good, but in some worlds i've got this problem (only where a long box lies on a long box).

I tried tune iterations and elasticIterations - for time 0.6 - only very big (900+) relevance values - and my fps falling to 4-6.

How can i use 30 fps with small iterations and have good speed in physic world ?

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

Re: mistake with iterations or time for step ?

Post by slembcke »

One of the best things that you can do to speed up Chipmunk is to use a constant sized timestep. Instead of passing the elapsed time to Chipmunk, figure out how many fixed size time steps you need to do in order to catch up. Basically you are running the physics speed independently of the framerate.

This is a good article on how to do that: http://gafferongames.com/game-physics/f ... -timestep/

Using a fixed size time step, you will be able to use fewer iterations and hopefully less CPU. For that many objects on the screen, I'd try using a physics step of 1/60 seconds with 5 - 10 iterations as a starting point. Also set elastic iterations to 0 if you don't have any bouncing objects as this will also make the simulation more stable and allow you to use less iterations.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
sja
Posts: 5
Joined: Wed May 13, 2009 4:46 pm
Contact:

Re: mistake with iterations or time for step ?

Post by sja »

slembcke, thank you for your answer.

Thanks for great info.
i'm trying use methods from your link - it's new for me.
but i have not achivied the desired result.

When i set elasticIterations to 0 my blocks go berserk. :)
I tried tune time put into cpSpaceStep:

1. With fps 30 i'm call:

cpSpaceStep(space, 1/60.0f);
cpSpaceStep(space, 1/60.0f);

2. With fps 60 i'm call:

cpSpaceStep(space, 1/60.0f);

the first method get the better results, but it's bad for me.

3. I'm tried to pick parameters in iterations and elasticIterations, but the good results gave very big values for my cpu :)

I've trying use cpSpaceResizeActiveHash(space, 100, 50); (with more values). How size of hash influence to the time of cpSpaceStep ?


And i can see this problem only when looong box (96x32) lies on a long box.
May be i don't try to change any main values ?

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

Re: mistake with iterations or time for step ?

Post by slembcke »

How exactly did they go berserk when you set elasticIterations to 0? That should work fine as long as iterations is not to small a number also.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
sja
Posts: 5
Joined: Wed May 13, 2009 4:46 pm
Contact:

Re: mistake with iterations or time for step ?

Post by sja »

I mean: my blocks behave as in the first message. If i set elasticElasticy =0, then my blocks shaking force.

Sorry, i didn't understand what you mean "That should work fine as long as iterations is not to small a number also".

How can i put more long blocks to long block ? I think my problem in small fps.
If i set fps to 60 for physic calculate my rendering fps falling to 4-6, but result of physic is not bad.
Where a soluition :) ?

thanks
User avatar
sja
Posts: 5
Joined: Wed May 13, 2009 4:46 pm
Contact:

Re: mistake with iterations or time for step ?

Post by sja »

I partly solved my problem: i've set mass of boxes = 0.1 (previous mass = 1), but i have trembled construction of my box's.
But it's not best solution. I've see my physic is not live :(
I've set elastic iterations to 0, and iterations to 10.
How i can make that my box's contruction was stable ?


I've got more iterations and more fps for have live physic, yes ?

thanks
Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests