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

feat(physics): Contact filtering + changing shape + jump through for simulated bodies #928

Merged
merged 5 commits into from
Mar 22, 2024

Conversation

MaxCWhitehead
Copy link
Collaborator

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.

contact events are not filtered, but solver contact forces are filtered
such that dynamic bodies do not collide with kinematics actors. Dynamics
only collide with tiles + solids.
if jump_through_body.is_some() {
let other_body = other_body.unwrap();

if other_body.linvel().y > 0.0 {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite correct, as if body is already inside jump through and starts falling, it will start colliding and pop downwards a bit faster than expected, but not too worried about that yet.

@zicklag zicklag added this pull request to the merge queue Mar 22, 2024
@zicklag
Copy link
Member

zicklag commented Mar 22, 2024

Sounds good!

Merged via the queue into fishfolk:main with commit 7ecca47 Mar 22, 2024
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants