-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store impulses in contacts and refactor contact data (#324)
# Objective Having access to contact impulses can be very useful for several tasks, like implementing destructable objects or determining how much damage a hit should deal. Currently, however, this is not really possible. There should be a way to access contact impulses. ## Solution Add properties for normal and tangent (i.e. friction) impulses to `ContactData`. These are computed for `PenetrationConstraint`s in the constraint solver and stored in `Collisions` in the new `SubstepSet::StoreImpulses` system set. The impulses can be accessed in `Collision` events or using the `Collisions` resource. Note that the impulses in `Colision` events are currently *only from the last substep*. Impulses are stored instead of forces for a few reasons: - It's more efficient internally, as it skips some operations - Impulses might make more sense for impacts - It's what e.g. Box2D and Unity use Computing the corresponding force is simple however, as you just need to divide by the (substep) delta time. For this, the contact types also have helpers like `normal_force` and `tangent_force`. --- ## Changelog - Added `SubstepSet::StoreImpulses` with a `store_contact_impulses` system - Added normal and tangent impulses and contact index to `ContactData` - Added total normal and tangent impulses to `Contacts` - Added manifold index to `ContactManifold` - Added collider entities and the contact manifold index to `PenetrationConstraint` - Added `SingleContact` struct, which is used by the `contact` query - Removed force properties from `PenetrationConstraint` in favor of impulses - Changed contact normal debug rendering to scale based on the impulse by default - Added `ContactGizmoScale` enum for configuring the scaling
- Loading branch information
Showing
9 changed files
with
331 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.