[SOLVED] Rigidbody/Ammo is not working properly

hello guys, im trying a simple gravity/collision/rigidbody moves and i found this problem, when box with collision and dynamic rigidbody falls on box with collision and dynamic r for and is on object for 2 seconds more and object below is destroyed the object above stays still and not falling.

https://launch.playcanvas.com/1118787?debug=true

https://playcanvas.com/editor/scene/1118787

I’m not sure how it works … but it’s likely related to an object getting frozen when it’s not moving. See example here, few second after the objects stops moving, they get frozen and change the color. Perhaps inspect the code to see if there’s some way to control it.
http://playcanvas.github.io/#physics/falling-shapes.html

It’s odd that deleting an entity next to another doesn’t cause nearby rigidbodies to ‘wake up’. :thinking:

To get around this, you can call https://developer.playcanvas.com/en/api/pc.RigidBodyComponent.html#activate on the entity that is ‘sleeping’.

@will Possible issue with the physics simulation?

1 Like

Thank you guys, we figured it out. But yes, it should at least “wake up” rigidbodies in area.

This is how Ammo works. Once a rigidbody falls asleep, it can only be awoken by either manually calling .activate(), or by some third force affecting it. Removing a rigidibody from the physics world (by disabling or destoying an entity) does not wake up other bodies.

3 Likes

Is that by design from Ammo/bullet?

Well, not exactly. This is a default way the rigidbodies created by the PlayCanvas engine and it is a preferred one, for performance optimization purposes. If one wants to, the body can be marked by a flag to never fall asleep. Then it will be aware of bodies disappearing under them. The CPU cost per frame is not worth it though, but probably there are valid cases, so here is a way to do it:

entity.rigidbody.body.setActivationState(pc.BODYSTATE_DISABLE_DEACTIVATION);
3 Likes

I was more thinking that when a rigidbody is removed from / added to the simulation, it should wake up nearby rigidbodies

1 Like

In Bullet engine, the default behavior is that the bodies form sleeping islands and if you activate a single body in that island by manually calling active() on it or by having some other object interacting with it, then the whole island wakes up. I just tested to activate a body before removing it, but it doesn’t wake up the body that is resting on top of it. Not sure if it is because of Bullet version in Ammo or something else.

1 Like

when you activated the body before removing, I assume a physics got evaluated? That could make a difference. So maybe enable, wait few frames (or one physics step) and then remove.

1 Like

@mvaligursky, right, I also thought it could be that it didn’t have time to process that, but adding half a second doesn’t change it - it still sleeps, even if I don’t remove the body, but just activate it. I think it is because we are trying to activate a static body (the box under), which I assume won’t work.

1 Like