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

Fix sleeping and collision event issues #112

Merged
merged 17 commits into from
Oct 14, 2023

Conversation

Jondolf
Copy link
Owner

@Jondolf Jondolf commented Aug 8, 2023

Objective

Fixes #161.

There are currently several issues with how collision events, CollidingEntities and sleeping are handled.

  • Removing a collider from underneath a sleeping body will leave that body floating in the air, because from the engine's perspective, the bodies aren't penetrating.
  • When a body is marked as sleeping, all of its collisions are discarded, and the CollisionEnded event is sent despite the bodies still being in contact from the user's perspective.
  • Collision events are being sent only if the bodies are penetrating during the last substep during a physics frame, which is often not the case, because most collisions should be solved by then. This can lead to missed collision events and issues with CollidingEntities not being updated.

Solution

This PR aims to fix all of these issues listed above.

Collision events are handled in a much more robust way. Contacts has during_current_frame, during_current_substep and during_previous_frame properties that are used to track when to send each type of collision event or update CollidingEntities. This also lets us remove PreviousCollisions.

Collisions against sleeping bodies are also handled better. When a collision against a sleeping body ends (through movement or despawn), the bodies are woken up. Collisions between bodies are also not discarded when they start sleeping.

@Jondolf Jondolf added C-Enhancement New feature or request bugfix A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality labels Aug 8, 2023
@Jondolf Jondolf merged commit edaad52 into main Oct 14, 2023
4 checks passed
@Jondolf Jondolf deleted the sleeping-and-collision-event-fixes branch October 14, 2023 14:04
@emarcotte
Copy link

BTW I updated my little game jam game to main after this merge and it worked very well. Thanks!

@Jondolf Jondolf added C-Bug Something isn't working and removed bugfix labels Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality C-Bug Something isn't working C-Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sometimes CollidingEntities will accumulate all the collided entities, sometimes not
2 participants