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.
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â.
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?
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.
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);
I was more thinking that when a rigidbody is removed from / added to the simulation, it should wake up nearby rigidbodies
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.
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.
@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.