Store impulses in contacts and refactor contact data #324
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 forPenetrationConstraint
s in the constraint solver and stored inCollisions
in the newSubstepSet::StoreImpulses
system set.The impulses can be accessed in
Collision
events or using theCollisions
resource. Note that the impulses inCollision
events are currently only from the last substep.Impulses are stored instead of forces for a few reasons:
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
andtangent_force
.Changelog
SubstepSet::StoreImpulses
with astore_contact_impulses
systemContactData
Contacts
ContactManifold
PenetrationConstraint
SingleContact
struct, which is used by thecontact
queryPenetrationConstraint
in favor of impulsesContactGizmoScale
enum for configuring the scaling