Collision Resolution - SC-SGS/surviving-sarntal GitHub Wiki

When a collision between two polygons is detected, the colliding objects are displaced to restore the validity of the current world state. Additionally, appropriate reactive impulses are applied.

Displacement

In addition to transferring the world back to a valid state, displacement serves the purpose of approximating the first point of contact between two objects. Only there, impulses can be applied accurately. Once a collision occurs, the colliding polygons are moved apart by the collision depth $\Delta$ along the collision normal. We weigh the displacement by mass to increase stability (c.f. Wheeler). $$ \vec{x}{ref}^{,+} = \vec{x}{ref}^{,-} + \Delta \cdot \frac{m_{ref}}{m_{ref} + m_{inc}} \cdot (1+\epsilon)\ \vec{x}{inc}^{,+} = \vec{x}{inc}^{,-} + \Delta \cdot \frac{m_{inc}}{m_{ref} + m_{inc}} \cdot (1+\epsilon) $$ The superscripts $^-$ and $^+$ denote the state before and after collision resolution. A small $\epsilon$ is introduced here and in the following equations to ensure stability.

If the collision was found by substepping, we first set the polygons to their positions at the time of the collision substep and then apply displacement from there.

Impulse Application

Not every contact is necessarily a collision. Only when rocks are moving towards one another at a contact point, we consider it a collision requiring the application of impulses. Fig. \ref{fig:CR} shows that this is the case, when the relative velocity $\vec{v}{rel}$ at the contact point $\vec{c}$ is opposed to the normal $\vec{n}$, i.e.: $$ \left<\vec{n},\vec{v{rel}}\right> = \left<\vec{n},\vec{v_{inc}}(\vec{c})-\vec{v_{ref}}(\vec{c})\right> < -\epsilon $$ where $$ \vec{v}(\vec{c}) = \frac{\vec{P}}{m} + \frac{L}{I} \left(\begin{array}{c c} 0 & -1\ 1 & 0 \end{array}\right) (\vec{c} - \vec{x}) $$ Finally, the impulse is applied to both the incident and the reference polygon. The formula for the magnitude $j$ of the impulse has been derived by Baraff: $$ j = \frac{-(1 + \gamma)\left<\vec{n},\vec{v_{rel}}\right>}{\Theta_{inc} + \Theta_{ref}} $$ with $$ \Theta = \frac{1}{m} + \left<\vec{n},\left(\frac{1}{I}((\vec{c} - \vec{x})\times \vec{n})\right)\times (\vec{c} - \vec{x})\right> $$ $\gamma \in [0, 1]$ is the coefficient of restitution. Intuitively, it describes how much of the impulse is preserved and how `bouncy` a collision is. The resulting impulse is applied as a surface force $-j\vec{n}$ for the reference polygon and $j\vec{n}$ for the incident polygon at the contact point $\vec{c}$. This force also generates a torque (see equation \ref{eq:forceToTorque}). The polygon experiences an instantaneous change in linear and angular momentum.

For terrain collisions, impulse and displacement are evidently only applied to the polygon and not on the terrain triangles which are static.

res

Figure: On the left, the polygons have been displaced to their first point of collision. $\vec{v}{rel}^{,-}$ is opposed to $\vec{n}$. The right side shows how the collision is resolved by applying impulses $\pm j\vec{n}$, so that $\vec{v}{rel}^{,+}$ is no longer opposed to $\vec{n}$.

$\rightarrow$ See how these methods are applied to game entities here.

⚠️ **GitHub.com Fallback** ⚠️