Enable / disable physics engine does not work

I have created a simple scene with 2 sphere and all I am doing is; I am call scene.enablePhysics() and scene.disablePhysicsEngine() when we click on the space bar; The scene works fine only on the initial load; once I disable the physics engine; there is no way to getting back to enabling it back again.
I know I am missing something basic :(.

Looking at the code, I think scene.disablePhysicsEngine would have been better named scene.disposePhysicsEngine. When called, it calls the underlying physicEngine.dispose, which in turn disposes all imposters. So the reason things stop working after calling is that the imposters no longer exist, even if physics engine is reenabled. Relevant code:

One option might be to recreate all your imposters when renabling? I created a simple PG here showing that works. It is similar to your original, but moves the spheres up so the physics are visible (or not), and also handles a potential minor issue with the the keyup listener that could cause confusion.

Perhaps you can explain your reasoning for wanting to disable/reenable the physics engine, and then others more familiar with it can give you some ideas.

1 Like

Thank you for the explanation; I will start using it this way.
The reason I was thinking of enabling / disabling physics is; I like the physics for its gravity and the “rigid” body implementation; but I dont like it for its bounce; since in my case I am creating a scene where the user is dragging and arranging stuff (furniture); so the physics rebound does not work very well sometimes.

What I am doing now is; disabling the physics when the user drags objects (using gizmo’s) and I am writing my wn “intersect” mesh logic (or also “movewithcollision” ) and once the user stops dragging; I want to re-apply physics; just incase some objects are in the air … they fall out of gravity to look more natural.
Please let me know if there are better options.

On a different note; (not sure how to pose this question); in order to save my CPU / laptop fan from going crazy; I am also building a logic to stop the engine.renderloop() and I enable the renderloop anytime the user clicks on the scene and then in a timeout I stop it after 300 ms. My question is: am I overthinking this ?; I wonder if I should experiment with “instances” and let the renderloop run for ever. Not sure if I am asking the correct question; but is leaving the engine.renderloop run forever – essentially bad if nothing in the scene is changing or does it not matter so much ? — apologies for asking this question within this problem (I will pose it in a different thread … if only I knew how to ask the question :)).

Thanks again

I think you can achieve this without disposing of your physics engine - have you tried putting your impostors to sleep?

1 Like

cc @Cedric

putting impostors to sleep doesn’t stop the physics. it stops the impostors, when woken up, they will be resetted. It means, putting into sleep a falling ball, then waking it up, the ball will have 0 speed and gravity will be applied.

I would suggest instead to set the time step to 0.

2 Likes

Hello @dhiru just checking in, was your question answered?