Defcronyke Posted June 11, 2017 Share Posted June 11, 2017 I am using CannonJS with BabylonJS, and I want to make a stack of 3 boxes, all the same size, but when I do, they slowly slide around until the stack topples. I have tried setting restitution to 0, and various values for gravity, mass, and friction, and regardless, the stack always topples itself undesirably. I only want them to topple when rammed with some other object. How can I achieve this? Quote Link to comment Share on other sites More sharing options...
fenomas Posted June 12, 2017 Share Posted June 12, 2017 We can't find the bug in code you don't post Here's a sample for what you're describing - how does your code differ from it? http://www.babylonjs-playground.com/#3AFJJ8 Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted June 12, 2017 Share Posted June 12, 2017 @fenomas I bet he's using square boxes, http://www.babylonjs-playground.com/#3AFJJ8#1 leave it for a minute and the boxes will have slided out of place by a little bit, leave it for 20+ 5'ish minutes and i bet they will have fallen down. i remember a simular post not so long ago, i believe it had something to do with gravity, but even at 0 gravity they slide, although it's much much slower than the above PG. Quote Link to comment Share on other sites More sharing options...
fenomas Posted June 12, 2017 Share Posted June 12, 2017 5 minutes ago, aWeirdo said: 5'ish minutes and i bet they will have fallen down. i remember a simular post not so long ago, i believe it had something to do with gravity Nothing to do with gravity, that's just due to the imprecise nature of integrated physics engines. The fix is: scene.getPhysicsEngine().getPhysicsPlugin().world.allowSleep = true Unless there's a known specific reason not to, BJS should probably set this by default... @Deltakosh aWeirdo 1 Quote Link to comment Share on other sites More sharing options...
aWeirdo Posted June 12, 2017 Share Posted June 12, 2017 21 minutes ago, fenomas said: Nothing to do with gravity, that's just due to the imprecise nature of integrated physics engines. The fix is: scene.getPhysicsEngine().getPhysicsPlugin().world.allowSleep = true Unless there's a known specific reason not to, BJS should probably set this by default... @Deltakosh i don't think they are being "allowed" to sleep, gravity is pushing on them and they are in constant collision with the other boxes, http://www.babylonjs-playground.com/#3AFJJ8#2 (increased gravity to speed up the effect) whatever it is, something isn't quite right edit; Ok, at around normal gravity with your line including the effect is almost gone, i can still see a very slight edge being made, but it's close to none, so unless it's a scene they will run for hours i think it's reasonable it could ofcourse also be from the first collision when the boxes were made, makes sense. Quote Link to comment Share on other sites More sharing options...
fenomas Posted June 12, 2017 Share Posted June 12, 2017 Yeah, physics engines are inherently not quite precise. If you drop one perfectly level box onto another, in general it still may shift a teeny bit due to, say, which order the vertices are processed in, or whatever. This is just part of how things work - in general the only thing that makes the simulation more precise is using smaller timesteps. As for sleep, all it does is suspend the simulation for bodies whose velocity/acceleration is smaller than some threshhold. So the simulation itself doesn't get any more precise, it just stops getting calculated when not needed. Quote Link to comment Share on other sites More sharing options...
Defcronyke Posted June 12, 2017 Author Share Posted June 12, 2017 13 hours ago, fenomas said: Nothing to do with gravity, that's just due to the imprecise nature of integrated physics engines. The fix is: scene.getPhysicsEngine().getPhysicsPlugin().world.allowSleep = true Unless there's a known specific reason not to, BJS should probably set this by default... @Deltakosh This fixed the issue, thank you! Additionally, to have my sphere player able to still move and not fall asleep along with the boxes, I had to do: sphere.physicsImpostor.physicsBody.allowSleep = false; Quote Link to comment Share on other sites More sharing options...
fenomas Posted June 13, 2017 Share Posted June 13, 2017 @Defcronyke The player body should wake up automatically if you move it in physics-friendly ways (like applying forces to it or moving it with joints). If you're manually changing its position property or similar, yeah, you may need to disable sleep for it - but this may cause other issues depending on what you're trying to do. If you have issues, there have been a couple of threads in the past about how best to move a player in a physics scene that might be helpful. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.