[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
Chipmunk Physics • View topic - n00b question about fixed timestep in Chipmunk

n00b question about fixed timestep in Chipmunk

Official forum for the .

n00b question about fixed timestep in Chipmunk

Postby shoggoth » Fri Dec 02, 2011 6:59 am

Hi there

I'm just starting to use Chipmunk and it looks great, nice work :)

Possibly missing something obvious here but other physics engines that I've used that prefer a fixed timestep take a call like step() with no parameters. I Notice that Chipmunk requires a parameter for its step such as step(1/60.0).

Is there an optimal value that I can pass as a parameter here? I've decoupled from the frame rate so I can tune the step to the physics engine. I'm currently stepping at 50Hz. How does Chipmunk know that the timestep is fixed? Does it compare to the previous value?

Thanks!
shoggoth
 
Posts: 4
Joined: Sat Aug 13, 2011 6:56 am

Re: n00b question about fixed timestep in Chipmunk

Postby gnasen » Fri Dec 02, 2011 10:40 am

If you use a fixed framerate like 30fps, you could pass 1/30 to chipmunk, because it makes sense to use the "standard physic values" . you could also pass any other value, but it may be much more difficult to do your calculations.
It is possible to use a dynamic timestep, but in this case your simulation is much more unstable.

so chipmunk doesnt know anything about your timings. Its just you to take care of it!
gnasen
 
Posts: 24
Joined: Wed Mar 16, 2011 12:17 pm

Re: n00b question about fixed timestep in Chipmunk

Postby slembcke » Fri Dec 02, 2011 12:18 pm

Chipmunk 6 does store the most recent timestep, you can get it using cpSpaceGetCurrentTimeStep() if you want. It's useful inside callbacks and such if you aren't using a strict fixed timestep. It uses this to attempt to retune the simulation if you use a dynamic timestep as well, but it's still recommended to avoid it.

The reason why Chipmunk recommends using a fixed timestep is because it caches the physics solution from the previous frame and uses that as the initial guess for the solution on the current frame instead of starting from 0. This allows the physics to be higher quality using less CPU. When you change the timestep each frame, the cached solution doesn't work as well and you will either have a less stable simulation or need to use more iterations (and CPU time) to make it stable.

By passing the timestep in each frame, it allows you to use a semi-dynamic timestep fairly easily when you want to do something like bullet time. Normally you'd be passing in something like 1/60 (or whatever your fixed timestep is), but when the game slows down you could pass in speedFactor/60.0 instead.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: n00b question about fixed timestep in Chipmunk

Postby shoggoth » Sat Dec 03, 2011 7:52 am

Thanks both for your replies, I understand now.
shoggoth
 
Posts: 4
Joined: Sat Aug 13, 2011 6:56 am

Re: n00b question about fixed timestep in Chipmunk

Postby jcmeyer5 » Thu Oct 11, 2012 7:14 pm

Okay, I am necro-ing this thread.

Up until today I have just updated physics in the game loop. I decided to go ahead and implement a separate scheduled method to update physics on a fixed 1/60 step. Now my shape and my sprite are out of sync... meaning the shape is leading the sprite when moving (all directions). It is slight, but definitely noticeable when debugDraw is on. If I leave the step in the main loop, the shape and the sprite sync perfectly. Both simulator and device.

Any ideas?
Chipmunk Pro and cocos2D 2.x branch for iOS development
jcmeyer5
 
Posts: 89
Joined: Thu Dec 15, 2011 9:18 am

Re: n00b question about fixed timestep in Chipmunk

Postby slembcke » Thu Oct 11, 2012 8:21 pm

Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: n00b question about fixed timestep in Chipmunk

Postby jcmeyer5 » Thu Oct 11, 2012 10:05 pm

Chipmunk Pro and cocos2D 2.x branch for iOS development
jcmeyer5
 
Posts: 89
Joined: Thu Dec 15, 2011 9:18 am

Re: n00b question about fixed timestep in Chipmunk

Postby jcmeyer5 » Fri Oct 12, 2012 7:25 am

Okay, so I see a difference with Angry Chipmunks and my chicken scratch. Angry Chipmunks is (through the ChipmunkCocosBody class) using the update function attached to the body. I didnt do that. I just set sprite location = body location in the update. Heck, I dont even think Angry Chipmunks used the update function (schedule step for physics, but not the ccnode built in update).

EDIT: DUH! You just built and scheduled your own update method. I did the same, but I was still running the original as well (so two update loops, update: and step:. So I just took the [space step:FIXED_STEP] and stuck it in the main update: loop. But I feel like I am just back where I started...
Chipmunk Pro and cocos2D 2.x branch for iOS development
jcmeyer5
 
Posts: 89
Joined: Thu Dec 15, 2011 9:18 am

Re: n00b question about fixed timestep in Chipmunk

Postby slembcke » Fri Oct 12, 2012 8:35 am

So do you still have an issue or not? I'm not sure if I follow.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: n00b question about fixed timestep in Chipmunk

Postby jcmeyer5 » Fri Oct 12, 2012 10:07 am

No, I think I am good now. Thanks for letting me confuse you.
Chipmunk Pro and cocos2D 2.x branch for iOS development
jcmeyer5
 
Posts: 89
Joined: Thu Dec 15, 2011 9:18 am

Next

Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 1 guest