Jump to content

Stacked boxes slide and topple when they should stay still


Defcronyke
 Share

Recommended Posts

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?

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 :P 

 

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 :D 
it could ofcourse also be from the first collision when the boxes were made, makes sense.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

 

Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...