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

Store impulses in contacts and refactor contact data #324

Merged
merged 3 commits into from
Feb 17, 2024
Merged

Conversation

Jondolf
Copy link
Owner

@Jondolf Jondolf commented Feb 16, 2024

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 PenetrationConstraints 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 Collision 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

@Jondolf Jondolf added C-Enhancement New feature or request A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on labels Feb 16, 2024
@Jondolf Jondolf merged commit 715b5b0 into main Feb 17, 2024
4 checks passed
@Jondolf Jondolf deleted the contact-impulses branch February 17, 2024 11:49
brianreavis pushed a commit to naturalatlas/bevy_xpbd that referenced this pull request Feb 17, 2024
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality A-Dynamics Relates to rigid body dynamics: motion, mass, constraint solving, joints, CCD, and so on C-Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant