feat(physics): Contact filtering + changing shape + jump through for simulated bodies #928
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.
Another chunk of features implemented to support ragdolls + dynamic bodies in Jumpy.
Contact filtering:
Add bit flags for rapier
CollisionGroup
andSolverGroup
.Jump Through for Dynamics:
Dynamics collide with jump through tiles. A contact modification physics hook is implemented so dynamics moving upward through jump throughs have contact thrown out, and kept when falling.
PhysicsHook
is used, and is only enable on dynamic bodies while they are simulating.Changing actor shape:
I found that using a capsule works better for player ragdoll then rectangle, which requires being able to change the shape of a collider. A helper function is added to do this correctly, changing shape is only currently supported for actors.
Handling
Stop
collision events for removed colliders:Changing an actor's shape involves removing collider and re-adding it. This triggers a stop event from rapier. These events provide collider handles, yet we map this to entities from userdata. The consequence of this is that when the stop event is dispatched, the collider handle is already invalid (generation incremented), meaning we no longer can access user data to determine what entity should be removed.
CollisionCache
that temporarily caches the handle + entity, which is used as fallback when receiving stop event if collider handle is not valid.This is not a great system, if someone removes a collider and does not call this, our collision event will not be removed causing bugs. Might be able to make this better, but for now will just have to make sure if we get fancy removing a collider (which is already a delicate / involved operation) this is called. The function to change actor shape calls this for us.