-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
[3.x] Enable setting of collision iterations in Physics2DServer #38387
Conversation
This allows fine-tuning of collision iterations for more accurate collision physics with a performance cost.
A more advanced approach would be to add a feature for adaptive collision iterations i.e. determining the number of iterations based on how many collisions there are/how fast objects are moving away from each other. That way collisions with lots of movement don't need that many iterations to work while mostly static collisions, like stacked boxes, need many iterations to help stabilize. Another option is to implement shock propagation, where rigid body collisions are ordered by position relative to collisions from forces against a static object, i.e. boxes from bottom to top due to a floor and gravity. There you treat the bottom box as an object with infinite mass with regard to linear velocity impulses and calculate the collisions from there. |
Is this related to godotengine/godot-proposals#204? (To close the proposal, this would need to be added to 3D physics as well.) |
Yeah it does seem related, though it seems that not only does this need to be added to 3D physics but also to the UI as well. Currently it can only be done by setting the server singleton's value in script. I also haven't looked too much into it but it seems bullets have their own separate physics system? |
I think this would make more sense as a Project Setting under Physics. I wouldn't expect this to be something that would need to be changed at runtime. |
Enabling a change of iterations at runtime can allow you to build an adaptive collision iteration system on top of it, as explained in my previous comment. If you know a particular frame has mostly dynamic objects at high speeds, you may want want to set the iterations low. If on the other hand you have a frame with a lot of mostly static bodies, higher iterations may be needed to keep things stable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but there should be a project setting to change this value without having to use a script. This can be merged to 3.3
safely as it won't impact existing functionality.
This PR doesn't add the feature to 3D, but I think having this in 2D only is better than not having it at all.
@pouleyKetchoupp Any comments?
Yeah the change looks good, although the PR should be done against master and cherry-picked for 3.3 since it affects only 2D (in 3D some file names have changed so it requires separate PRs). The same change in 3D and project settings would make a lot of sense but these can be added later. |
Would it make sense to have this as a per-object property? Then when constraint islands are generated, the max number of iterations out of all the objects in the island could be used for solving it. |
It might be useful in specific cases, but it's hard to say. It makes sense to start with a global value so it's easy to set, then possibly a separate proposal for per-object settings if it's needed in some use cases. |
So IIUC this is pending on a |
Yeah, there's no reason for this change to be 3.x specific. |
@Rhathe Switching the branch directly doesn't work too well, better to open a new PR on master. |
Thanks! |
This allows fine-tuning of collision iterations for more accurate collision physics with a performance cost.
Reading through the physics code it seems to be using sequential impulses, so even with higher iterations it's not guaranteed to be completely reliable, but it will help especially if you know your scenes will have a high number of stacking collisions.
Mitigates #2092. Found that the current iteration number of 8 leads to the bug immediately on load, setting it to 12 with
Physics2DServer.set_collision_iterations(12)
makes it not collapse immediately on my machine.May help with #38339.
3.x version of #48827