Hi Ray,
You mention in your book that there's a better way of handling the timestep available online at:
http://gafferongames.com/game-physics/f ... -timestep/
After poring over the link for a while, I can't figure out how to actually integrate it with Space Viking in place of the existing update method. Would you be able to show us how? It would be a fantastic learning opportunity. Thanks as always for your time!
Fixed Timestep
6 posts
• Page 1 of 1
Re: Fixed Timestep
@BeeZee,
Have you compared the "before" and "after" of the Update routine? As they mention a lot of the strange behavior was fixed.
As I understand the routine, it's a matter of how you slice up time. How many intervals per fraction of time? The article would be updating the code from 12.25. But, I was pretty satisfied with 12.25 as I worked through the book.
Have you compared the "before" and "after" of the Update routine? As they mention a lot of the strange behavior was fixed.
As I understand the routine, it's a matter of how you slice up time. How many intervals per fraction of time? The article would be updating the code from 12.25. But, I was pretty satisfied with 12.25 as I worked through the book.
- larry
- Uber Haxx0r
- Posts: 296
- Joined: Sun Oct 09, 2011 6:11 am
- Has thanked: 2 times
- Been thanked: 29 times
Re: Fixed Timestep
@larry is correct by specifying the time in which your update method is called, it will fix a lot of issues. The article just highlights the need to tweak how often your update method is called.
-

n_dubbs - Forum Subject Matter Expert
- Posts: 885
- Joined: Fri Feb 18, 2011 7:17 pm
- Location: Pittsburgh, PA
- Has thanked: 0 time
- Been thanked: 33 times
Re: Fixed Timestep
Thanks for the responses! I'm still very confused on how to implement a solution like what the linked article is proposing, though. The fixed time step provided in the book is below:
This seems easy enough to use. Right afterwards, however, it suggests:
The linked article seems like a really interesting thing to explore, but its implementation is a lot more theoretical and is pretty far above the level of understanding I'm at after reading the book. There seem to be a lot of these discussions online, but all the ones I've been finding apply to different languages. Since the book makes mention of it, I think it would be awesome to dive in further and try to get it working with Cocos2D on iOS.
- Code: Select all
static double UPDATE_INTERVAL = 1.0f/60.0f;
static double MAX_CYCLES_PER_FRAME = 5;
static double timeAccumulator = 0;

timeAccumulator += dt;
if (timeAccumulator > (MAX_CYCLES_PER_FRAME * UPDATE_INTERVAL)) {
timeAccumulator = UPDATE_INTERVAL;
}
int32 velocityIterations = 3;
int32 positionIterations = 2;
while (timeAccumulator >= UPDATE_INTERVAL) {
timeAccumulator -= UPDATE_INTERVAL;
world->Step(UPDATE_INTERVAL,
velocityIterations, positionIterations);
}
This seems easy enough to use. Right afterwards, however, it suggests:
There is one further optimization you can do to your physics loop: interpolate the results to remove the effects of that tiny extra slice of time in each frame. For more information on how to do this, check out http://gafferongames.com/game-physics/f ... -timestep/ or search the Cocos2D forums for a good discussion.
The linked article seems like a really interesting thing to explore, but its implementation is a lot more theoretical and is pretty far above the level of understanding I'm at after reading the book. There seem to be a lot of these discussions online, but all the ones I've been finding apply to different languages. Since the book makes mention of it, I think it would be awesome to dive in further and try to get it working with Cocos2D on iOS.
Re: Fixed Timestep
I found a really good implementation of this here, if anyone's interested:
http://www.cocos2d-iphone.org/forum/topic/8922
It wasn't too hard to get this running in place of the existing code. I'd be happy to help if anyone needs assistance figuring out how to use it.
http://www.cocos2d-iphone.org/forum/topic/8922
It wasn't too hard to get this running in place of the existing code. I'd be happy to help if anyone needs assistance figuring out how to use it.
Re: Fixed Timestep
@BeeZee thanks for sharing! 
-

n_dubbs - Forum Subject Matter Expert
- Posts: 885
- Joined: Fri Feb 18, 2011 7:17 pm
- Location: Pittsburgh, PA
- Has thanked: 0 time
- Been thanked: 33 times
6 posts
• Page 1 of 1
Return to Learning Cocos2D Book Official Forum
Who is online
Users browsing this forum: No registered users and 1 guest