How to single-step simulation?

Is there a way (e.g. from Python script) to pause/single-step/resume the physics simulation, while keeping the rendering and inputs active?

Thanks for any ideas.

yea,

blender have a “LogicTicRate”, “PhysicsTicRate”,
“MaxLogicFrame” and “MaxPhysicsFrame” that you can
change using the followings syntax respectively :

setLogicTicRate(60)
setPhysicsTicRate(60)
setMaxLogicFrame(1…5)
setMaxPhysicsFrame(1…5)

I guess one of them can probably help ya

Thanks for responding. I did see those functions, but:
setLogicTicRate(60) – I don’t want to slow down the logic part
setPhysicsTicRate(60) – docs say this is not implemented (2.49 at least)
setMaxPhysicsFrame(1…5) – even at the minimum of 1 this won’t help

Well… it depends on what (in the scene with the physics) needs to keep going.

You could probably have one scene be purely the physics objects, then use a Pause Scene actuator. Your input/controls/other displays can be on an overlay scene.

To resume, use the resume scene actuator. To skip a single frame, resume the scene AND send a message, and in the resumed scene check for that message… it’ll go through one frame and then pause again.

So basically, you have your input on one scene (the overlay), and then all of your “simulation” on the other scene.

Obviously, if you NEED to control objects IN the same scene as the simulations, you might run into problems… but there could be workarounds.

If my solution isn’t sufficient, maybe a more complete explanation of what you want to do would be good?

-Sam

You could probably have one scene be purely the physics objects, then use a Pause Scene actuator. Your input/controls/other displays can be on an overlay scene.

Aha, thanks. Doesn’t completely solve my problem, but might be a starting point.

I’m doing a visualization of a robot, where the robot control is a separate program communicating over a socket to Blender via a Python script. Ideally, the external program could control the simulation updates while inputs and rendering of the 3D display (in particular, virtual camera control) stays active.

There’s also an object.suspendDynamics() function. If you call this on all of your physics objects, they should be “paused” in their physics, and then calling restoreDynamics() should allow them to continue.

You could do something like this:


#Pause physics
for obj in GameLogic.getCurrentScene().getObjectList():
     obj.suspendDynamics()

#Restore physics
for obj in GameLogic.getCurrentScene().getObjectList():
     obj.restoreDynamics()

Try it out!

More documentation: http://www.blender.org/documentation/249PythonDoc/GE/index.html

-Sam

   		There's also an object.suspendDynamics() function.

Awesome, it looks like that will do the trick! That plus sending a message (or maybe a state change) on restoreDynamics() should allow a “single-step” mode.

Thanks very much.