moai / moai-dev

This is the development repo of Moai SDK.
http://getmoai.com
938 stars 314 forks source link

No menthod for setting Box2D timestep #436

Open BlueByLiquid opened 12 years ago

BlueByLiquid commented 12 years ago

You can set velocity and position iterations but not timestep. This is very limiting.

pygy commented 12 years ago

Are you referring to this? http://gafferongames.com/game-physics/fix-your-timestep/

BlueByLiquid commented 12 years ago

I am talking about the first variable in the box2d world's "Step" function. I am assuming that article is talking about a similar concept.

You would normally do something like the following in box2d: world.Step(timeStep, velocityIterations, positionIterations);

pygy commented 12 years ago

Isn't this covered by MOAISim.setStep() and .setMultiplier()? http://getmoai.com/docs/class_m_o_a_i_sim.html#ae864c88e384d1f4c01ee2feac35d7e08

If the documentation isn't clear (it isn't for me), someone just posted a question about it in the forums: http://getmoai.com/forums/moaisim-setstepmultiplier-t1069/

BlueByLiquid commented 12 years ago

I will check. I'm not sure. Thanks for the info

patrickmeehan commented 12 years ago

Box2D should use the global sim step, which can which is a fixed interval by default. Agree that the docs are unclear - I am flagging this as a bug just to remind me to clarify this in the docs.

BlueByLiquid commented 12 years ago

@partric, is the global sim step used for something else other than the box2d step? If so I would recommend seperating it because you might want to operated the physics sim at a different rate than other things for a number of reasons.

patrickmeehan commented 12 years ago

Yes, it's used for the animation system and timers. Will look into letting you set box2D's step independently.

patrickmeehan commented 11 years ago

So now that I'm getting back to this stuff... the discussion of different time steps running concurrently makes me want to generalize the whole notion. The purpose of the sim object is to manage how system time gets subdivided into simulation time - and there are a bunch of different options it allows for doing that.

I think this issue is really a feature, not a bug, and the right way to implement will be to rethink MOAISim as a subclass of MOAIAction instead of a singleton. The idea is that the system timestep flows into the base of the action tree. It is then up to each action to modify the timestep for use by its children (and to iterate those child actions multiple times if required). So maybe the new class is MOAISimTimer... to run the physics at a different rate than the animation you'd just create two instances of MOAISimTimer and make sure your animations spawn under one and your physics runs under the other.

Anyway, it will be a little time before I can get to this. For the short term, unless there's a real reason not to, adjust the MOAISim to whatever makes sense for your physics. The animation system should be able to run at more or less any rate without stability issues. And I agree that a fixed step is the best configuration for both unless there's a pressing reason to use variable step (and the boost, multiplier options don't meet your needs).

BlueByLiquid commented 11 years ago

Thanks for the update Patrick. Setting the step for physics to pretty high is needed for good rope simulations and that number is often much higher than what is wanted for animations. This probably wasn't noticed as few people are using ropes because of the other rope joint issue.

patrickmeehan commented 11 years ago

OK, thanks for clarifying. Will try to get to this feature as soon as I can after this round of bug fixes. :)

BlueByLiquid commented 11 years ago

Thanks!

On Tue, Oct 16, 2012 at 12:24 PM, Patrick Meehan notifications@github.comwrote:

OK, thanks for clarifying. Will try to get to this feature as soon as I can after this round of bug fixes. :)

— Reply to this email directly or view it on GitHubhttps://github.com/moai/moai-dev/issues/436#issuecomment-9498784.

sclark39 commented 9 years ago

Since I found this post while looking into how to make a matrix style bullet-time effect, I thought it would be good to add some info here for the solution I found in case it helps someone else:

If you need to slow down the physics simulation, it can be achieved by throttling the box2d coroutine (e.g. world:throttle(0.2) ). By doing it like this rather than adjusting the MOAISim step directly you can keep the game running at a smooth 60 fps, but each of those frames would only move the physics simulation forward at 20% of normal speed.

Warning: This would likely invalidate any guarantees of determinism. :)