Rigid body game physics 4
29 Nov 2019part 1 part 2 part 3 part 4 part 5 part 6
Update: See Getting started with the Jolt Physics Engine
The following article is partially based on Hubert Eichner’s article on inequality constraints.
Inequality Constraints for Colliding Contacts
At a colliding contact the relative speed of the two objects is negative. I.e. a contact is a colliding (and not a resting) contact if the normal speed at the contact point is below a small negative threshold. Colliding contacts have restitution, i.e. the collision is partially elastic and the two objects will separate after the collision. The colliding contacts and affected joints are handled using a special time step of zero duration. Again the inequality constraint is The linear and angular components of J are the same as for a resting contact. The correction term b however depends on the initial normal speed at the contact point vn and the restitution coefficient ε:
Sequential Impulses for Collisions
Again the contact and joint impulses are estimated iteratively. Note that the normal speed vn at each contact is determined beforehand and stays constant during the iterations.
- determine vn for all colliding contacts
- for each iteration
- for each joint
- compute Jacobian J and correction vector b
- predict speed u
- compute λ
- compute the impulse P
- add P to accumulated impulses of the two objects
- for each colliding contact
- subtract old impulses P from previous iteration from accumulated impulses of the two objects
- compute Jacobian J and correction vector b
- predict speed u
- compute new λ and clip it to be greater or equal to zero
- compute the impulse P
- add P to accumulated impulses of the two objects
- for each joint
- apply impulses to objects
The value λ is stored as Pn for limiting friction impulses lateron. The time step here is zero! Therefore external forces do not need to be considered while handling collisions. An object falling to the floor will experience several collisions until the linear and angular speed has decreased sufficiently for the contacts to become resting contacts.