Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Technique used in manipulation demo is insufficient to wake sleeping bodies #875

Open
lostfictions opened this issue May 16, 2020 · 3 comments · May be fixed by #877
Open

Technique used in manipulation demo is insufficient to wake sleeping bodies #875

lostfictions opened this issue May 16, 2020 · 3 comments · May be fixed by #877

Comments

@lostfictions
Copy link

lostfictions commented May 16, 2020

Hey there, thanks for this library! I really appreciate how well-structured and documented everything is.

I saw in #532 (and in other issues) that to allow programmatically-moved bodies to wake sleeping bodies, their velocity should manually be set as well as their position. Unfortunately, it doesn't actually seem like this is sufficient. I've made a repro case here by changing the manipulation demo a bit: https://codesandbox.io/s/elegant-ellis-kihf9?file=/src/index.js

The dynamic box on top of the programmatically-moved static box should fall asleep, at which point no more collisions will happen (and it'll just hang in space). The T-shaped compound on the right will also happily pass through any sleeping bodies it collides with.

image

Does something else need to be done? It's not clear to me if there's any way for non-dynamic bodies to even manually disable sleeping on other bodies, since no collision events ever fire.

@lostfictions
Copy link
Author

lostfictions commented May 16, 2020

Looks like this condition at the beginning of Detector.collisions is preventing static-on-sleeping collisions from being recognized:

if ((bodyA.isStatic || bodyA.isSleeping) && (bodyB.isStatic || bodyB.isSleeping))
continue;

I changed that to the following:

-  if ((bodyA.isStatic || bodyA.isSleeping) && (bodyB.isStatic || bodyB.isSleeping))
+  if ((bodyA.isSleeping && bodyB.isSleeping) || (bodyA.isStatic && bodyB.isStatic))

and that was enough to allow collision events to fire between a programmatically-moved static body and a dynamic sleeping body, though it doesn't wake the sleeping body (but at that point it's easy to wake it in the collision event). It didn't seem to cause any spurious events if a body comes to rest against, say, a static floor and falls asleep, though I didn't test much more thoroughly. Happy to submit a PR if this is a desirable fix!

@lostfictions
Copy link
Author

Hey @liabru, I proposed (what I think is) a relatively non-disruptive solution to this issue in #877 -- any chance you could give feedback on that?

@bill-shuzai
Copy link

bill-shuzai commented Jan 16, 2023

Is there a final solution to this problem?

Recently I developed a project with creating multiple bodies, they are not static. And after each few seconds there will be a new body(isStatic) was manipulated to hit those non-static bodies, you know, like a snooker game.

But because I created a lot of bodies and they keep colliding each others,so I was thinking to improve performance by using enableSleeping, then I have the same problem that when a new body start to hit those sleeping bodies,it just stoped and overlapped on them. It seems that setting different collision filter on them.

how can i solve this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants