I think you should probably leave disablePrestep set to false for at least one full frame, as the synchronization (with the physics engine) likely happens each frame.
I found another method that works well, but the dispose() function doesn’t seem to work.
My InitMotor() function create motor with constraints and … with imports different parts of the model using separate ImportMeshAsync calls (for example: body, wheels, etc.). After that, I use the convertToMesh() function to merge the meshes into a single one for easier manipulation and physics.
When I try to reset the motor (after it flips or gets stuck), I call dispose() on the merged mesh before reinitializing. However, it seems like the original meshes from the import are not actually disposed, and they remain in the scene or memory.
if (restartGame) {
// not work
bodyMesh.dispose();
// create motor again
await initialMotor(bodyMesh.position.x);
}
What didn’t work? Try disablePrestep = false; and never set it to true. See my link if you really want to reset it back to True. You can’t just set disablePrestep, change transformation, reset disablePrestep, as @qq2315137135 said and as I mention in the link: prestep must be set for an entire frame.
Your issues are going to be difficult to debug without some kind of playground.
“Why isn’t it doing exactly as I want?”
“Because it’s doing exactly as you said.”
“But I told Babylon to do exactly as I want.”
Sometimes it’s very difficult to distinguish between a Babylon bug, a user error, or our own misunderstanding of what you’re intending. A playground helps greatly to delineate. Plus you’ll sometimes solve your own problem by having something simplified to play around with.
On the practical side, helping those who are trying to help you can lead to faster responses from a wider group of volunteers.
In that case Body and Shape still exist in the physics world so it can be a collider with other bodies. If it’s not an issue, then it’s the way to go.