Allow Forces to wake or not wake up bodies#783
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
#770 added a
ForceshelperQueryDatafor applying forces, impulses, and accelerations to dynamic bodies. The intent was that forces would wake up bodies by default, but this was actually not the case, asForceshas some components that sleeping bodies don't.However, we should also have a way to allow forces not to wake up bodies. This can be important for optimization in some cases.
Solution
Rework
Forcesto wake up bodies by default when applying non-zero forces, impulses, or accelerations. Additionally, add aForcesItem::non_wakingmethod that returns aNonWakingForcesItem. The two force types share aRigidBodyForcestrait and the same API, but the former wakes up bodies while the latter doesn't.The API looks like this:
Many existing physics engines instead take a boolean argument in all force methods to control whether the force should wake the body up. However, I am of the opinion that sleeping should primarily be transparent to the user and just an internal optimization, and that intuitively you would expect a force or impulse to always have an effect on a body by default. Disabling waking for a force should be a more advanced use case, so it should not affect the common API.
Game engines like Unity and Godot actually seem to always wake up bodies for non-zero forces, with no option to configure this. I took the middle route, defaulting to waking up, but having an additional
non_wakingmethod to opt in to the non-waking behavior.I considered some component-driven approaches like a
ForceWakingModecomponent, but I think this needs to be easily configurable per force and not a persisted per-entity setting.