-
-
Notifications
You must be signed in to change notification settings - Fork 132
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
Implement sleeping #32
Merged
Conversation
This file contains 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
Everything should be working and documented now. I'll merge this, feel free to open issues if you encounter any problems. |
Bodies marked as sleeping are not simulated by the physics engine. Bodies are marked as sleeping when their velocity is below the `SleepingThreshold` for a duration indicated by `DeactivationTime`. Bodies are woken up when they interact with active bodies, when gravity changes or when the body's position, rotation, velocity etc. are changed.
There wasn't a good logical place for it, so I think a separate plugin makes sense for now. It helps keep things modular as well. It can be moved to a better place later if there is one.
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.
Depends on #31.
Description
Implements sleeping to improve performance and reduce small jitter.
Bodies with the
Sleeping
component are not simulated by the physics engine. Bodies are marked with the component when their linear and angular velocities are below the values of theSleepingThreshold
resource for a duration indicated by theDeactivationTime
resource.The
TimeSleeping
component is used to track the time that the velocity has been below the threshold, and it is reset to 0 whenever the threshold is exceeded.Bodies are woken up when they interact with active dynamic or kinematic bodies or joints, or when gravity changes, or when the body's position, rotation, velocity, or external forces are changed.
Sleeping can be disabled for all bodies with a negative sleeping threshold, and for specific entities with the
SleepingDisabled
component.Examples
Below is the current behaviour in a couple examples. The red color indicates that a body is sleeping and isn't being simulated.
First, the
cubes
example. At the end I change the velocity of the boxes. Sleeping doesn't help keep the cube stack stable unless a really high sleeping threshold is specified, but it does help keep them still on the ground.2023-06-08.13-59-25.mp4
move_marbles
example:2023-06-08.14-38-15.mp4
Considerations and future improvements
cubes
example, sleeping doesn't fix jittery collisions (Unstable collisions #2). However, it does help keep slowly drifting bodies still, so in many cases it might be enough until a proper fix for unstable collisions is found.SleepingThreshold
should perhaps be scaled depending on the world scale, e.g. in 2D, objects might be hundreds of pixels wide, so a threshold of 0.1 would be tiny. Maybe we should introduce aPhysicsScale
resource, similar to rapier?Todo