fishfolk / jumpy

Tactical 2D shooter in fishy pixels style. Made with Rust-lang 🦀 and Bevy 🪶
https://fishfolk.org/games/jumpy/
Other
1.6k stars 115 forks source link

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

Closed MaxCWhitehead closed 4 months ago

MaxCWhitehead commented 4 months ago

Another chunk of features implemented to support ragdolls + dynamic bodies in Jumpy.

Contact filtering:

Add bit flags for rapier CollisionGroup and SolverGroup.

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.

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.

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.

zicklag commented 4 months ago

Sounds good!