-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Stop reporting contacts for sleeping bodies when using Jolt Physics (reverted) #100533
Conversation
Thanks! |
Thanks @mihe for the fast fix. But let me leave here my thoughts:
Example: Let's assume you have a player that only jumps if no contacts are reported, and for some reason it is stopped and hanging in a rope. It enters sleep mode. Suddenly the player can jump. This can lead to all sort of bugs in games. I hope it's easy to cache the contact points before sleeping and make the engine return them even in sleep mode as the default physics engine did! |
I appreciate the feedback, @NatGazer, and I can certainly see the argument for wanting contacts to be reported even when sleeping. I am somewhat torn on what to do. The current behavior of Godot Physics could arguably be considered buggy to begin with, as the contacts that it persists after the body has gone to sleep are in fact stale. For example, if you have a (This is a bit of a contrived example, I'll admit, but the same thing can happen with sleeping bodies resting against eachother in general.) It might be possible to emulate the behavior of Godot Physics with Jolt, by just ignoring all of Jolt's contact callbacks for sleeping bodies, but the question is whether we would actually want to. Looking at Bullet in Godot 3, it seems that Bullet does in fact update its list of contact manifolds even for sleeping bodies, so while you do still get the behavior of the |
Well, but the object staying mid air happens both on Godot Physics and Jolt Physics. This is another issue.
Yes, we should avoid this. A sleeping body should have minimal logic. But I believe it should cache the previous collision points and return them if requested anyway. Otherwise, if any implementation requires the user to have constant feedback on contact points, he will be forced to make the rigid-body never sleep, or to cache the last contact points reported before sleep. I don't know who worked in Godot Physics at the time, maybe someone can have a word about this. I just think it will be very confusing to the user see the object stopped reporting contacts just because it is not moving. Specially for those not aware rigid bodies enter sleep mode. |
I've put up another pull request (#100701) which effectively reverts this one, and instead does exactly what Godot Physics does, which is to only clear the list of contacts while a body is awake. The issue of potentially stale contacts seems like the lesser evil in this case, and the argument for compatibility with Godot Physics is undoubtedly a strong one either way. I also realized there was a "regression" introduced by this PR for contact reporting with |
Fixes #100515.
It seems that Jolt's contact listener can end up reporting contacts for bodies only to later in the simulation step decide that the body is inactive/sleeping. This meant that we ended up hanging on to the contacts for the first physics frame of sleeping, and since we don't call the state synchronization callback after that first sleeping physics frame we'd get stale values cached in the
RigidBody3D
node, leading to the issue seen in #100515.This PR resolves this by checking to see whether the body did in fact end up sleeping once we flush the accumulated contacts in
JoltContactListener3D::_flush_contacts()
, which prevents sleeping bodies from reporting contacts at all.Note that this does differ a bit from how things behave in Godot Physics, as Godot Physics seems to report (stale?) contacts for sleeping bodies, but since Jolt won't call the contact listener callbacks for sleeping bodies we don't have much of a choice, and frankly I don't think anyone would expect (or even want) contacts to be reported for sleeping bodies anyway.