Another chunk of features implemented to support ragdolls + dynamic bodies in Jumpy.
Contact filtering:
Add bit flags for rapier CollisionGroup and SolverGroup.
The Collision group filters both contact forces and events, these are configured such that there is no change here in collision events.
Solver group then filters contact forces, this is used to make sure dynamic actors only simulate collision with tiles (solid + jump through) and solids, not other kinematic (or dynamic) actors.
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.
Only the contact filtering 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.
We now have a function that should be called on removal of collider in 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.
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.